Copy Code code as follows:
#-*-coding:cp936-*-
Import Sys
Import Urllib2
Import JSON
From PYQT4 import Qtcore, Qtgui
Class Mywindow (Qtgui.qlcdnumber,qtgui.qwidget):
def __init__ (self, Parent=none):
Super (Mywindow,self). __init__ (parent)
Self.setwindowtitle ("Weather")
Self.resize (100,40)
Self.setnumdigits (0)
Self.setwindowflags (QtCore.Qt.FramelessWindowHint)
Self.setwindowopacity (0.5)
url = ' http://m.weather.com.cn/data/101090502.html '
re = Urllib2.urlopen (URL). Read ()
We = json.loads (re) [' Weatherinfo ']
Label1 = Qtgui.qlabel (we[' city ')
Label2 = Qtgui.qlabel (we[' date ')
Label3 = Qtgui.qlabel (we[' Week ')
Label4 = Qtgui.qlabel (we[' Temp1 ')
Label5 = Qtgui.qlabel (we[' weather1 ')
#---------Add Table layout
GridLayout = Qtgui.qgridlayout ()
Gridlayout.addwidget (label1, 0, 0)
Gridlayout.addwidget (Label2, 0, 1)
Gridlayout.addwidget (label3, 0, 2)
Gridlayout.addwidget (label4, 0, 3)
Gridlayout.addwidget (Label5, 0, 4)
Self.setlayout (GridLayout)
def mousepressevent (self,event):
If Event.button () ==qtcore.qt.leftbutton:
Self.dragposition=event.globalpos ()-self.framegeometry (). TopLeft ()
Event.accept ()
If Event.button () ==qtcore.qt.rightbutton:
Self.close ()
def mousemoveevent (self,event):
If Event.buttons () & QtCore.Qt.LeftButton:
Self.move (Event.globalpos ()-self.dragposition)
Event.accept ()
App = Qtgui.qapplication (SYS.ARGV)
Demo = Mywindow ()
Demo.show ()
APP.EXEC_ ()