Tôi mới sử dụng Python và WX. Tôi đã tạo một hộp thoại thử nghiệm đơn giản được hiển thị bên dưới để nhắc người dùng bằng hộp tổ hợp. Tôi muốn nắm bắt giá trị từ combox trong chương trình chính của tôi. Làm thế nào để tôi gọi nó từ chương trình chính của tôi?Python WX - Trả về đầu vào của người dùng từ wx Hộp thoại
Đây là cách tôi đã purposing gọi nó là hiển thị hộp thoại nhưng hiện không nắm bắt được giá trị từ combobox:
import highlight
highlight.create(self).Show(True)
a = highlight.OnComboBox1Combobox(self)
print a
Tên của tập tin Dialog là "nổi bật". Bên dưới là mã:
#Boa:Dialog:Dialog2
import wx
def create(parent):
return Dialog2(parent)
[wxID_DIALOG2, wxID_DIALOG2COMBOBOX1, wxID_DIALOG2STATICTEXT1,
] = [wx.NewId() for _init_ctrls in range(3)]
class Dialog2(wx.Dialog):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Dialog.__init__(self, id=wxID_DIALOG2, name='', parent=prnt,
pos=wx.Point(264, 140), size=wx.Size(400, 485),
style=wx.DEFAULT_DIALOG_STYLE, title='Dialog2')
self.SetClientSize(wx.Size(384, 447))
self.comboBox1 = wx.ComboBox(choices=['test1', 'test2'],
id=wxID_DIALOG2COMBOBOX1, name='comboBox1', parent=self,
pos=wx.Point(120, 16), size=wx.Size(130, 21), style=0,
value=u'wining\n')
self.comboBox1.SetToolTipString(u'comboBox1')
self.comboBox1.SetLabel(u'wining\n')
self.comboBox1.Bind(wx.EVT_COMBOBOX, self.OnComboBox1Combobox,
id=wxID_DIALOG2COMBOBOX1)
self.staticText1 = wx.StaticText(id=wxID_DIALOG2STATICTEXT1,
label=u'test', name='staticText1', parent=self, pos=wx.Point(88,
16), size=wx.Size(19, 13), style=0)
def __init__(self, parent):
self._init_ctrls(parent)
##print get_selection
##print get_selection1
def OnComboBox1Combobox(self, event):
get_selection = self.comboBox1.GetValue()
return get_selection
Mike, Cảm ơn bạn đã trả lời. Khi tôi sử dụng res = myDlg.ShowModal() nó không hoạt động nhưng nếu tôi thay đổi nó thành res <> myDlg.ShowModal() nó hoạt động. Bạn có biết tại sao? Cảm ơn. – user1314011
Nó sẽ hoạt động. Tôi cần một ví dụ runnable và traceback để biết những gì đang xảy ra. –
nó sẽ là tốt để thêm những gì mã cần phải được trong hộp thoại tùy chỉnh cũng như các ứng dụng chính. Câu hỏi OPs không được đề cập trong ví dụ về hộp thoại tùy chỉnh zetcode – Anake