1
我剛開始使用wxPython,並且遇到綁定問題。wxPython:如何綁定按鈕?
通常我發現綁定一個按鈕事件的例子是用self.Bind(wx.EVT_BUTTON, self.OnWhatEverFunction, button)
完成的。我有一個框架,裏面有一個面板,還有一個按鈕,以及我曾經試過的,結果總是閃爍的幀,瞬間出現,就是這樣。由於代碼沒有那麼多,所以我將它附加在這裏,並希望你們中的一位能向我展示解決我的小問題的方法。
由於提前, 托馬斯
#!/usr/bin/python
import wx
class CPFSFrame(wx.Frame):
def __init__(self, parent, title):
super(CPFSFrame, self).__init__(parent, title=title,
style = wx.BORDER | wx.CAPTION | wx.SYSTEM_MENU | wx.CLOSE_BOX,
size=(350, 200))
panel = wx.Panel(self, -1)
pNumberLabel = wx.StaticText(panel, -1, 'Project number: ')
pNumberText = wx.TextCtrl(panel, -1, '', size=(175, -1))
pNumberText.SetInsertionPoint(0)
pNameLabel = wx.StaticText(panel, -1, 'Project name: ')
pNameText = wx.TextCtrl(panel, -1, '', size=(175, -1))
pNameText.SetInsertionPoint(0)
pButton = wx.Button(panel, label='Create')
pButton.Bind(wx.EVT_BUTTON, self.OnCreate)
sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
sizer.AddMany([pNumberLabel, pNumberText, pNameLabel, pNameText, pButton])
panel.SetSizer(sizer)
statusBar = self.CreateStatusBar()
def OnCreate(self, evt):
self.Close(True)
self.Centre()
self.Show()
if __name__ == '__main__':
app = wx.App()
CPFSFrame(None, title='Create New Project Folder Structure')
app.MainLoop()
感謝邁克, 做同樣的self.Centre()甚至出現在正確的位置上的幀之後。 :D 我調用了函數OnCreate,因爲它爲一個新項目創建了整個目錄結構。 self.Close()只是一個虛擬的東西,看它是否有效。 乾杯托馬斯 –