【问题标题】:How to open up a new child window when a button is clicked? (wxpython)单击按钮时如何打开一个新的子窗口? (wxpython)
【发布时间】:2012-07-09 21:58:18
【问题描述】:

在主窗口中单击按钮时如何打开子框架? 下面的代码创建了一个下拉框。我的问题是我的主窗口有一个单独的类,我不知道如何在我的主应用程序中打开这个新的下拉框窗口。 主窗口只是一个添加了按钮的 wx.frame。

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()

【问题讨论】:

  • ummm someOtherDialog.Show() 或 someOtherDialog.ShowModal()....也许我不明白你的问题...
  • @JoranBeasley 我希望现在清楚,我编辑了我的问题

标签: python user-interface wxpython


【解决方案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()

【讨论】:

  • 感谢我是 python 新手,没想到要放主类的按钮
猜你喜欢
  • 2019-04-12
  • 2020-11-14
  • 2015-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多