wxPython和PyQt的Hello World例子比较

wxPython和PyQt分别是wxWidgets和Qt的python绑定,wxWidgets和Qt都是跨平台的GUI库,不过前者是开源免费的,而后者是基于商业License
让我们分别看看wxPython和PyQt的Hello World程序

[b]wxPython[/b]
首先去[url]http://www.python.org[/url]下载Windows下的python2.5,然后去[url]http://www.wxpython.org[/url]下载相应的Windows安装包
装好后写个hellowx.py看看效果:
[code]
import wx

class MyFrame(wx.Frame):
def __init__(self, parent, title):

wx.Frame.__init__(self, parent, -1, title, pos=(150, 150), size=(350, 200))

menuBar = wx.MenuBar()
self.SetMenuBar(menuBar)
menu = wx.Menu()
menu.Append(wx.ID_EXIT, "E&xit", "Exit this application")
self.Bind(wx.EVT_MENU, self.OnTimeToClose, id=wx.ID_EXIT)
menuBar.Append(menu, "&File")

panel = wx.Panel(self)
text = wx.StaticText(panel, -1, "Hello wxPython!")
text.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
text.SetSize(text.GetBestSize())
panel.Layout()

def OnTimeToClose(self, evt):
self.Close()

class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, "Hello wxPython!")
self.SetTopWindow(frame)
frame.Show(True)
return True

app = MyApp()
app.MainLoop()
[/code]
App->Frame->MenuBar/Panel,结构很清晰

[b]PyQt[/b]
去[url]http://www.quadgames.com/download/pythonqt/[/url]下载Windows的PyQt安装包,PyQtGPL10.exe目前只支持到Python2.4
然后写个helloqt.py看看效果:
[code]
import sys
from qt import *

class HelloButton(QPushButton):
def __init__(self, *args):
QPushButton.__init__(self, *args)
self.setText("Hello World")

class HelloWindow(QMainWindow):
def __init__(self, *args):
QMainWindow.__init__(self, *args)
self.button = HelloButton(self)
self.setCentralWidget(self.button)

def main(args):
app = QApplication(args)
win = HelloWindow()
win.show()
app.connect(app, SIGNAL("lastWindowClosed()"),
app, SLOT("quit()"))
app.exec_loop()

if __name__ == "__main__":
main(sys.argv)
[/code]
也是App->Window->MenuBar的模式,同wx没多大区别

[b]体验[/b]
总体觉得Qt的类名起的有点怪异,wxPython看起来很优美
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值