Example of PyQt4 real time display text content GUI


First, create a txt.py file to save the contents of the crawler

#! /usr/bin/env python
# -*- coding: utf-8 -*-
Txt_name = ['photographer Li Xiaolei',
   'match Hanfeng',
   'Shi Yong Gang',
   'CCTV5 sports news',
   'Yoga Lin',
   'Hangzhou Weibo city event',
   'May days',
   'beauty's new vision',
   'talk about your feelings',
   'CCTV news',
   'Jia Ling',
   'released in Guangzhou, China',
   'Ding Wen',
   'azurejk 柾 tianguguo resources Expo',
   'Zhang Jie',
   'selected abstracts',
   'satellite TV reveals secrets',
Txt = ['ා Li Xiaolei photography class ා record the most beautiful moment, recommended by students all over the country. [winking] Figure 1: Xi'an student @ yuan Xiaochen Er Figure 2: Guangzhou student @ is ﹣ Ye Zi Figure 3: Jiangsu student @ Four Brothers Figure 4: Hebei student @ Zi Yu smile can use blank space to show artistic conception for photos of large scenes, but I prefer to capture the eyes of characters and the main body to make the photos more memorable. [winking] I will always do a good job in teaching and establish a good learning circle so that students can be stronger and better than blue. Every day, I spend half a day on the worktable. ',
  Match Star: it's not easy to talk about the beauty and whiteness of the goddess who looks very good in both light and plain makeup,
  Lippi: I absolutely don't know how I, as an old coach in Guangzhou, chose me to go to the Central Committee? So Comrade Cai Zhenhua talked to me and said that it's all up to you. When you come to be the head coach, I said that you should be smart. I'm not really modest. How did a Guangzhou coach come to Beijing? However, comrade Zhenhua said that "we have made a decision through research." at that time, I read two poems: "if we want to benefit our country, we should not avoid it because of misfortune and fortune." ',
  '[Lippi signed a contract with the football association to officially coach national football team Scolari to stay at Evergrande] Lippi finally arrived. Lippi arrived in Hong Kong yesterday and was picked up by Vice President Liu Yongzhu of Evergrande, who then returned to Guangzhou together. Today Lippi had a secret meeting with Xu Jiayin and Cai Zhenhua, chairman of the Chinese Football Association, who was waiting in Guangzhou. The three exchanged views on the future of Chinese football. Lippi also signed a contract with the Chinese Football Association in Guangzhou. He has officially become the head coach of the Chinese national team. And Scolari will remain Evergrande without any accident. ',
  'a big heart to the hard work of Wuhan subway last night. Thank you for letting my fans go home safely. Thank you very much. Wuhan?
  '[2016 China's top 100 cities list: 8 cities in Zhejiang ranked No. 8 [hold]] [Hangzhou's side events] recently, 2016 China's top 100 cities list was released, including 8 cities in Hangzhou, Ningbo, Wenzhou, Shaoxing, Jiaxing, Jinhua, Taizhou and Huzhou, among which Hangzhou ranked No. 8 in the total list, up 1 place compared with the previous year. Beijing, Shanghai and Guangzhou continue to rank in the top three. O2016 China's top 100 cities Zhejiang 8 cities on the list your hometown on the list? ',
  'thank you Malaysia! This beautiful night, let's drink with cool coconut water and warm Kuala Lumpur? Some people don't take coconut water. May day 2016 is a concert. 10 / 29, Quanzhou, 11 / 5, Changsha ',
  'Zheng Shuang, a little flower of the post-90s generation. In just a few years, she has become a hot actress, starring in a number of films and TV plays not only well-known, but also these works are the golden TV audience champions. Recently, the participation of "a little smile is very city" is to deepen the audience's love for her. @Zhengshuang studio @ zhengshuang bar, zhengshuang ',
  'never doubt yourself because of other people's words, nor belittle yourself because of who you like. All your advantages and disadvantages are prepared to accept the person you are. You know, everyone wants to be a better person, but that doesn't mean you're not worth being loved. ',
  [the girl who insisted on dancing in the square jumped out of the vest line] a little girl born in Hangzhou in 1992, because the leading dance of dancing in the square near her home was good-looking, she was attracted and danced in the square. The little girl stopped drinking and had half a bowl of rice for dinner. In less than a year, from 110 Jin to 86 Jin, 24 Jin less, even the vest line! Doctor: that's the saying "keep your mouth shut and your legs open.". (Qianjiang Evening News) O insists on dancing in the square. After 90, the girl jumped out of the vest line ',
  '[frost comes, protect these parts] ① abdomen: don't expose the abdomen, cover the quilt at night, and put on clothes at night; ② feet: shoes should be warm, comfortable, dry, and soaked in hot water properly; ③ knees: don't expose knee joints easily, don't exercise excessively, and the elderly can wear knee pads when necessary. Frost day gradually cold, forward to remind people around [heart]! ',
  'the first staff meeting of Da Wan - a complete system. I'd like to introduce you one by one. Picture 1: Chairman of Dawan entertainment ~ spring flowers picture 2: CEO of Dawan entertainment @ Li kuntu picture 3: CCO of Dawan entertainment @ sun Jibin picture 4: VP of Dawan entertainment @ Dawan Fang Xintu picture 5: Czo artist director of Dawan entertainment @ Zhang Wener here thank you for clothing sponsorship Bao bell advertising: @ happy spy is broadcasting in Youku ',
  It's a 24-hour open bookstore in Guangzhou. There are dozens of people who want to sleep here all night, or to read, experience, or... In the past three years, tens of thousands of people have spent at least one night in his shop... Where is ta? Do you have a late night experience? What other open bookstores do you have in Guangzhou? The bookworms share with the night owls,
  'those faces that cannot be recalled',
  'ාtian 柾 country beginාtian 柾 country music center 柾 country special MC cut [f Tian 柾 country begin] oil pipe OFFICIAL MV [O web link] (part of Translation: Hello? I'm from the bulletproof Youth League. I'll show three kinds of coquettish sets. I'll shoot videos in L seconds. ',
  'Yang Yang's wife is the only one who can like this micro blog. In 10s, Yang Yang's wife can like to lose 10 Jin and find a thin shop,
  "Now I have to announce my official account. I have some feelings of self abandon [hee hee], and see your dialogue with me [laughter cry] I want... I think [snickering] there's good news. You who didn't get the ticket have a chance to [applaud] ',
  'for so many years, you have been living in seclusion in my heart. I have laid down heaven and earth, everything, but I have never laid down you. I walk all the way in the world, walking against the time, only to meet you in this life. I have laid down the world but never laid down you,
  'Zhong Hanliang, an orphan, doesn't admire himself. Zhong Hanliang, a strange fate, allows the world to turn a hundred times, doesn't change his original intention, and never fails. The ancient costume war love drama "Gufang doesn't admire herself" starring Zhong Hanliang and Yang Ying has exposed some of its flowers at the Haikou Investment Promotion Conference of Hunan Satellite TV today. It is magnificent, exquisite and beautiful. The handsome prince Chu is brave and affectionate. It is expected to land in the Golden Eagle solo theater of Hunan Satellite TV in the Spring Festival of 2017! @ Zhong Hanliang ',
  [tearful] ']
Txt_key = ['photography mood capture',
   'light make-up and plain look',
   'central state of Guangzhou',
   "Lippi Evergrande signed a contract to coach",
   'Wuhan fans',
   'top 100 cities Hangzhou side events list',
   'Kuala Lumpur concert in Malaysia',
   'Zheng Shuang's films and TV plays are hot',
   'doubt of speech',
   'square dance, vest line leading dance',
   'frost keeps warm old man',
   'staff meeting system entertainment',
   'the bookstore stays open all night',
   'Tian Zhenguo Video Music',
   Yang Yang likes it,
   The official account is disliked by good news.
   'road time Cangyangjiacuo',
   "Zhong Hanliang, Gu Fang, Hunan Satellite TV, doesn't admire himself.",
   'Zhang Yixing burst into tears']

Then create a Weibo gui.py for GUI page design:

#! /usr/bin/env python
# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
import time
import txt
class MyWidget(QtGui.QWidget):
 def __init__(self, parent=None):
  super(MyWidget, self).__init__(parent)
  #self.resize(800, 500)
  Self.setwindowtitle ('show popular Weibo content in real time ')
  self.timer = QtCore.QTimer()
  #Display Weibo content
  self.txt = QtGui.QTextEdit()
  #Display Weibo keywords
  self.txt_key = QtGui.QLineEdit()
  #Show microblog users
  self.txt_name = QtGui.QLineEdit()
  Label1 = qtgui.qlabel ("Weibo user name:")
  Label2 = qtgui.qlabel ("keyword:")
  Label3 = qtgui.qlabel ("Weibo content:")
  Otherlabel = qtgui.qlabel ("note:")
  otherLabel.setFrameStyle(QtGui.QFrame.Panel | QtGui.QFrame.Sunken)
  labelCol = 0
  contentCol = 1
  leftLayout = QtGui.QGridLayout()
  leftLayout.addWidget(label1, 0, labelCol)
  leftLayout.addWidget(self.txt_name, 0, contentCol, 1, 40)
  leftLayout.addWidget(label2, 1, labelCol)
  leftLayout.addWidget(self.txt_key, 1, contentCol, 1, 40)
  leftLayout.addWidget(label3, 2, labelCol)
  leftLayout.addWidget(self.txt, 2, contentCol, 1, 40)
  leftLayout.addWidget(otherLabel, 5, labelCol, 1, 40)
  leftLayout.setColumnStretch(0, 1)
  leftLayout.setColumnStretch(1, 3)
  Self.ok Bu button = qtgui.qpushbutton ("start Crawler", self)
  Self.closepushbutton = qtgui.qpushbutton ("close", self)
  rightLayout = QtGui.QVBoxLayout()
  mainLayout = QtGui.QGridLayout(self)
  mainLayout.addLayout(leftLayout, 0, 0)
  mainLayout.addLayout(rightLayout, 0, 1)
  self.connect(self.ok_button, QtCore.SIGNAL('clicked()'),self, QtCore.SLOT("on_ok_button_clicked()"))
  self.connect(self.closePushButton, QtCore.SIGNAL("clicked()"), self, QtCore.SLOT("close()"))
 #Custom slot function to implement crawler
 def on_ok_button_clicked(self):
  for i in range(len(txt.txt)):
   #Add content
   self.txt.setText(' '+txt.txt[i])
   #The following two statements are used to set the display time of a single microblog
if __name__ == "__main__":
 import sys
 app = QtGui.QApplication(sys.argv)
 w = MyWidget()

The display effect is as follows (Note: different contents can be displayed every four seconds, which can be set in the program):

The above example of PyQt4 real-time display text content GUI is all the content shared by Xiaobian. I hope it can give you a reference, and I hope you can support developepaer more.