# -*- coding: utf-8 -*-
import wx
class Main(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, size=(430,550))
self.mainPanel = wx.Panel(self, size=(0,500))
self.data1 = [1,2,3]
self.data2 = ['google','amazon']
self.listCtrl = wx.ListCtrl(self.mainPanel, size=(0,0), style=wx.LC_REPORT|wx.BORDER_SUNKEN)
self.listCtrl.InsertColumn(0, 'ONE', format=wx.LIST_FORMAT_CENTRE, width=wx.LIST_AUTOSIZE_USEHEADER)
self.listCtrl.InsertColumn(1, 'TWO', format=wx.LIST_FORMAT_CENTRE, width=wx.LIST_AUTOSIZE)
self.listCtrl.InsertColumn(2, 'THREE', format=wx.LIST_FORMAT_CENTRE, width=wx.LIST_AUTOSIZE)
self.ComboBoxs = wx.ComboBox(self.mainPanel, choices=self.data2, style=wx.CB_READONLY)
self.ComboBoxs.Bind(wx.EVT_COMBOBOX, self.ComboSelect, self.ComboBoxs)
self.textLabel = wx.StaticText(self.mainPanel)
self.autoRefreshCount = 0
self.BoxSizer = wx.BoxSizer(wx.VERTICAL)
self.BoxSizer.Add(self.ComboBoxs, 0, wx.ALL, 5)
self.BoxSizer.Add(self.listCtrl, 1, wx.EXPAND | wx.ALL, 5)
self.BoxSizer.Add(self.textLabel, 0, wx.EXPAND | wx.ALL, 5)
self.mainPanel.SetSizer(self.BoxSizer)
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.autoRefresh, self.timer)
self.timer.Start(5000)
self.ComboSelect(self)
def ComboSelect(self, event):
self.listCtrl.Append(self.data1)
def autoRefresh(self, evnet):
if self.ComboBoxs.GetStringSelection() in self.data2:
self.ComboSelect(self)
self.textLabel.SetLabel('count : ' + str(self.autoRefreshCount))
self.autoRefreshCount += 1
else:
self.textLabel.SetLabel('count : ' + str(0))
self.autoRefreshCount = 0
if __name__ == '__main__':
app = wx.App()
frame = Main()
frame.Show(True)
app.MainLoop()
J'ai créé une importation automatique après la valeur de sélection de zone de liste déroulante.Comment puis-je obtenir la sélection combo wxpython et modifier la valeur?
Si le problème modifie la sélection de la zone de liste déroulante, la valeur modifiée self.textLabel.SetLabel ('count:' + str (self.autoRefreshCount))
doit être initialisée. J'ai essayé beaucoup mais je ne sais pas comment faire.
if self.ComboBoxs.GetStringSelection() in self.data2:
Il semble y avoir un problème dans l'expression conditionnelle.
Merci encore. J'ai beaucoup appris de toi encore une fois. Je pensais qu'il y avait une valeur médiane qui a changé quand la boîte de combo a changé, mais ce n'était pas le cas. Passez une bonne journée :) –
Voir mon edit à propos de 'EVT_TEXT' –