2012-07-09 97 views
1

如何在主窗口上單擊按鈕時打開子框架? 下面的代碼創建一個下拉框。我的問題是我有一個單獨的主窗口類,我不知道如何在我的主應用程序中打開這個新的下拉框窗口。 主窗口只是一個添加了按鈕的wx.frame。我能在幾分鐘)單擊按鈕時如何打開新的子窗口? (wxpython)

import wx 
class MyFrame(wx.Frame): 

    def __init__(self): 
     wx.Frame.__init__(self, None, -1, 'wxChoice test', size=(300, 150)) 
     colorList = ['blue','green','yellow','red'] 
     # create the dropdown box 
     self.choice1 = wx.Choice(self, -1, choices=colorList) 

     # select item 1 = 'green' to show 
     self.choice1.SetSelection(1) 
     # set focus to receive optional keyboard input 
     # eg. type r for red, y for yellow 
     self.choice1.SetFocus() 
     # new event handler wxPython version 2.5 and higher 
     self.choice1.Bind(wx.EVT_CHOICE, self.onChoice) 
    def onChoice(self, event): 
     '''get the slected color choice''' 
     self.color = self.choice1.GetStringSelection() 
     self.SetTitle(self.color) # test 



# this is only a small application 
application = wx.PySimpleApp() 
# call class MyFrame 
frame1 = MyFrame() 
# show the frame 
frame1.Show(True) 
# start the event loop 
application.MainLoop() 
+0

嗯'someOtherDialog.Show()'或'someOtherDialog.ShowModal('....也許我不明白你的問題... – 2012-07-09 22:01:57

+0

@JoranBeasley我希望現在清楚,我編輯了我的問題 – user1401950 2012-07-09 22:10:53

回答

1

簡單的例子 進口WX

def show_other(evt): 
    f2 = wx.Frame(None,-1) 
    c = wx.Choice(f2,-1,choices=['red','blue','green']) 
    f2.Show() 

a = wx.App(redirect = False) 


f = wx.Frame(None,-1) 
b = wx.Button(f,wx.ID_OK) 
b.Bind(wx.EVT_BUTTON,show_other) 
f.Show() 
a.MainLoop() 
+0

謝謝我是python的新手,並沒有想到把按鈕放在主類 – user1401950 2012-07-09 22:19:46

相關問題