如何使用用户输入更新 TextControl 值
How do I update TextControl value with user input
我有一个带有文本控件的 Python 表单,当用户点击保存时,它需要保存到 SQL table。唯一保存的字段是我使用 SetValue()(author_field 和 sate_field)并具有默认值的字段。如果用户更改了这些字段,我该如何将其保存到 SQL?我需要更改事件吗?
author_field=wx.TextCtrl(panel, pos=(20, 40))
species_field=wx.ComboBox(panel, pos=(150, 40), choices = row)
location_field=wx.TextCtrl(panel, pos=(20, 100))
date_field = wx.adv.DatePickerCtrl(panel, pos=(150, 100))
author_field.SetValue(getpass.getuser()) #AD user
date_field.SetValue(now)
auth=author_field.GetValue()
datefield=date_field.GetValue()
spec=species_field.GetValue()
locatval=location_field.GetValue()```
我有它的工作。
self.author_field=wx.TextCtrl(panel, wx.ID_ANY, getpass.getuser(), pos=(20, 40))
self.species_field=wx.ComboBox(panel, wx.ID_ANY, pos=(150, 40), choices = row)
self.location_field=wx.TextCtrl(panel, wx.ID_ANY, pos=(20, 100))
self.date_field = wx.adv.DatePickerCtrl(panel, wx.ID_ANY, now, pos=(150, 100))
SaveData = wx.Button(panel, label='Save', pos=(20, 140))
SaveData.Bind(wx.EVT_BUTTON, self.SaveSQL)
def SaveSQL(self, e):
if self.location_field.Value is not None:
conn = pymssql.connect("server name", "database", "username", "password")
cursor = conn.cursor()
sql_insert_query = """INSERT INTO Table ([User], DateEntered, SpeciesID, [Location]) VALUES (%s, %s, %s, %s)"""
insert_tuple = (self.author_field.Value, self._wxdate2pydate(self.date_field.Value), self.species_field.Value, self.location_field.Value)
result = cursor.execute(sql_insert_query, insert_tuple)
conn.commit()
cursor.close()
wx.MessageBox('Form Saved', 'Info', wx.OK | wx.ICON_INFORMATION)
elif self.location_field.Value is None:
wx.MessageBox('Please select Species', 'Info', wx.OK | wx.ICON_INFORMATION)
return
我有一个带有文本控件的 Python 表单,当用户点击保存时,它需要保存到 SQL table。唯一保存的字段是我使用 SetValue()(author_field 和 sate_field)并具有默认值的字段。如果用户更改了这些字段,我该如何将其保存到 SQL?我需要更改事件吗?
author_field=wx.TextCtrl(panel, pos=(20, 40))
species_field=wx.ComboBox(panel, pos=(150, 40), choices = row)
location_field=wx.TextCtrl(panel, pos=(20, 100))
date_field = wx.adv.DatePickerCtrl(panel, pos=(150, 100))
author_field.SetValue(getpass.getuser()) #AD user
date_field.SetValue(now)
auth=author_field.GetValue()
datefield=date_field.GetValue()
spec=species_field.GetValue()
locatval=location_field.GetValue()```
我有它的工作。
self.author_field=wx.TextCtrl(panel, wx.ID_ANY, getpass.getuser(), pos=(20, 40))
self.species_field=wx.ComboBox(panel, wx.ID_ANY, pos=(150, 40), choices = row)
self.location_field=wx.TextCtrl(panel, wx.ID_ANY, pos=(20, 100))
self.date_field = wx.adv.DatePickerCtrl(panel, wx.ID_ANY, now, pos=(150, 100))
SaveData = wx.Button(panel, label='Save', pos=(20, 140))
SaveData.Bind(wx.EVT_BUTTON, self.SaveSQL)
def SaveSQL(self, e):
if self.location_field.Value is not None:
conn = pymssql.connect("server name", "database", "username", "password")
cursor = conn.cursor()
sql_insert_query = """INSERT INTO Table ([User], DateEntered, SpeciesID, [Location]) VALUES (%s, %s, %s, %s)"""
insert_tuple = (self.author_field.Value, self._wxdate2pydate(self.date_field.Value), self.species_field.Value, self.location_field.Value)
result = cursor.execute(sql_insert_query, insert_tuple)
conn.commit()
cursor.close()
wx.MessageBox('Form Saved', 'Info', wx.OK | wx.ICON_INFORMATION)
elif self.location_field.Value is None:
wx.MessageBox('Please select Species', 'Info', wx.OK | wx.ICON_INFORMATION)
return