日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

wxpython入门_wxpython笔记:Wxpython入门

發布時間:2023/12/10 python 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 wxpython入门_wxpython笔记:Wxpython入门 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#!/usr/bin/env?python

'''靜態文本、可控文本、對話框、GetApp()'''

importwx,time

ID_EXIT=200ID_ABOUT=201

class Frame(wx.Frame): #2?wx.Frame子類

def __init__(self,parent = None,id = -1,title ='wxPython!'):

wx.Frame.__init__(self,parent,id,title,size=(500,500))

self.setupStatusBar()

self.InitButton()

self.InitMenu()#設置狀態欄

defsetupStatusBar(self):#狀態欄

sb = self.CreateStatusBar(2) #2代表將狀態欄分為兩個

self.SetStatusWidths([-1, -2]) #比例為1:2

self.SetStatusText("Ready", 0) #0代表第一個欄,Ready為內容

#timmer

self.timer =wx.PyTimer(self.Notify)

self.timer.Start(1000, wx.TIMER_CONTINUOUS)

self.Notify()#處理事件

defOnclick(self,event):if event.GetEventObject()==self._submit_btn:

dlg=LoginDiglog(None,-1)

dlg.ShowModal()

dlg.Destroy()#實時顯示時間

defNotify(self):

t=time.localtime(time.time())

st=time.strftime('%Y-%m-%d %H:%M:%S',t)

self.SetStatusText(st,1)#這里的1代表將時間放入狀態欄的第二部分上

defInitButton(self):#顯示按鈕功能

self.panel=wx.Panel(self,-1)

wx.StaticText(self.panel,label="Username",pos=(20,20))

wx.StaticText(self.panel, label="Password", pos=(20, 50))

self._username=wx.TextCtrl(self.panel,pos=(85,15))

self._passwd= wx.TextCtrl(self.panel, pos=(85, 45),style=wx.TE_PASSWORD)

self._submit_btn=wx.Button(self.panel,label=u'提交',pos=(20,80),size=(50,30))

self.panel.Bind(wx.EVT_BUTTON,self.Onclick,self._submit_btn)defGetUsername(self):returnself._username.GetValue()defGetPasswd(self):returnself._passwd.GetValue()defInitMenu(self):#主菜單

menubar =wx.MenuBar()#子菜單:退出(Quit)

fmennu =wx.Menu()

fmennu.Append(ID_EXIT, u'退出(&Q)', 'Terminate thr program')

menubar.Append(fmennu, u'文件(&F)') #將子菜單添加到文件(File)中

#子菜單:關于(About)

hmenu =wx.Menu()

hmenu.Append(ID_ABOUT, u'關于(&A)', 'More information about this program')

menubar.Append(hmenu, u'幫助(&H)') #將子菜單添加到幫助(Help)中

self.SetMenuBar(menubar)#綁定子菜單

wx.EVT_MENU(self, ID_EXIT, self.OnMenuExit)

wx.EVT_MENU(self, ID_ABOUT, self.OnMenuAbout)

wx.EVT_CLOSE(self, self.OnCloseWindow)defOnMenuExit(self,event):

self.Close()defOnMenuAbout(self,event):

dlg=AboutDialog(None,-1)

dlg.ShowModal()

dlg.Destroy()defOnCloseWindow(self,event):

self.Destroy()classLoginDiglog(wx.Dialog):def __init__(self,parent,id):#super(LoginDiglog,self).__init__(parent,id,u"顯示",size=(200,200))

wx.Dialog.__init__(self, parent, id, '顯示', size=(200, 200))

self.app=wx.GetApp()

self.panel=self.app.frame

self._username_dlg=wx.StaticText(self,label=u'用戶名:'+self.GetUsername(),pos=(20,20))

self._passwd_dlg=wx.StaticText(self,label=u'密碼:'+self.GetPasswd(),pos=(20,50))

wx.Button(self,wx.ID_OK,pos=(20,80))defGetUsername(self):returnself.panel.GetUsername()defGetPasswd(self):returnself.panel.GetPasswd()classAboutDialog(wx.Dialog):def __init__(self,parent,id):

wx.Dialog.__init__(self,parent,id,'About Me',size=(200,200))#BoxSizer為一個盒子,wx.VERTICAL

self.sizer1=wx.BoxSizer(wx.VERTICAL)

self.sizer1.Add(wx.StaticText(self,-1,u'wxPython初級教程'),0,wx.ALIGN_CENTER_HORIZONTAL|wx.TOP,border=20)

self.sizer1.Add(wx.StaticText(self,-1, u'wxPython初級教程'), 0, wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=10)

self.sizer1.Add(wx.StaticText(self,-1, u'wxPython初級教程'), 0, wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=10)

self.sizer1.Add(wx.StaticText(self,-1, u'wxPython初級教程'), 0, wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border=10)

self.sizer1.Add(wx.Button(self,wx.ID_OK),0,wx.ALIGN_CENTER|wx.BOTTOM,border=20)

self.SetSizer(self.sizer1)class App(wx.App): #5?wx.App子類

def __init__(self):#如果要重寫__init__,必須調用wx.App的__init__,否則OnInit方法不會被調用

wx.App.__init__(self)defOnInit(self):

self.frame=Frame()

self.SetTopWindow(self.frame)

self.frame.Show()returnTrueif __name__=="__main__":

app=App()

app.MainLoop()

總結

以上是生活随笔為你收集整理的wxpython入门_wxpython笔记:Wxpython入门的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。