SingleChoiceDialog未显示在顶级框架中

时间:2018-03-20 13:05:33

标签: python wxpython

我已经在Wxpython中为SingleChoiceDialog编写了代码

import wx

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "My Choose_List Frame", size =(300,300))

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

        self.choose_list = wx.SingleChoiceDialog(self.panel,'Wt things u want do in u r life?','single Choice', ['Eating','Drinking', 'Working'])
        if self.choose_list == wx.ID_OK:
            resp = self.choose_list.GetSelections()
            print resp


if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = MyFrame()
    frame.Show()
    app.MainLoop()

但是在顶层框架中,SingleChoiceDialog没有显示。

任何人都可以帮忙吗? 感谢

1 个答案:

答案 0 :(得分:0)

您忘记了Show() / ShowModal()对话框 我也改变了选择 我单一选择没有GetSelections()方法 它将有GetSelection(),但只返回选择的索引 相反,使用GetStringSelection()运行,这当然总是返回"饮用",只是开玩笑;)

import wx

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "My Choose_List Frame", size =(300,300))

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

        self.choose_list = wx.SingleChoiceDialog(self.panel,'Wt things u want do in u r life?','single Choice', ['Eating','Drinking', 'Working'])

        if self.choose_list.ShowModal() == wx.ID_OK:
            resp = self.choose_list.GetStringSelection()
            print resp


if __name__ == '__main__':
    app = wx.App()
    frame = MyFrame()
    frame.Show()
    app.MainLoop()