对于使用触发事件来反应的按钮传递参数如下:
可以通过lambda对function的参数传递 :
t.Bind(wx.EVT_BUTTON, lambda x, textctrl=t: self.input_fun(event=x, textctrl=textctrl))
前提需要self.input_fun(self,event,t):传入参数
而同时两个Frame之间的参数传递可以通过回调函数。
def check_filelist_fun(self, event):
self.check_filelist_bt.Enable(False)
F = Frame_Update(self.check_filelist_bt, filepath_list=self.filelist_dict, call=self.Callback_value)#另外的Frame2,使用函数调用Frame2的值def Callback_value(self, value):
self.filelist_dict = value
print(self.filelist_dict)在Frame2上
class Frame_Update(wx.Frame):
def __init__(self, outputbt, filepath_list, call):
wx.Frame.__init__(self, None, -1, 'xxxxx', size=(580, 540),
style=wx.CAPTION | wx.MINIMIZE_BOX | wx.CLOSE_BOX | wx.SYSTEM_MENU |wx.STAY_ON_TOP
)
self.outputbt = outputbt
self.filepath_list = filepath_list
self.call = call
self.call(self.filepath_list)#函数回传
要获取Frame2上的变量,可以通过实例化Frame2时上调用callback_value函数进行参数回传,
import wx
from Frame_Update import Frame_Update
import images
class Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'generate the email tools', size=(580, 540),
style=wx.CAPTION | wx.MINIMIZE_BOX | wx.CLOSE_BOX | wx.SYSTEM_MENU
)
self.panel = wx.Panel(self, -1)
self.logo = wx.StaticBitmap(self, -1, images.piclogo.GetBitmap(), pos=(140, 30))
self.inputtext = wx.StaticText(self, -1, '请选择导入的文件类型', pos=(40, 140))
filename_list = ['xxxxxxxx','dsdf','sdfas','dsafs']
self.filelist_dict = {i: '' for i in filename_list}
self.choose_filepath_box = wx.ComboBox(self, -1, pos=(40, 160),
choices=filename_list, style=wx.CB_READONLY)
self.inputfile = wx.Button(self, -1, '导入', pos=(280, 160), size=(90, 30))
self.check_filelist_bt = wx.Button(self, -1, '检查文件路径', pos=(380, 160), size=(90, 30))
self.check_filelist_bt.Bind(wx.EVT_BUTTON, self.check_filelist_fun)
self.inputfile.Bind(wx.EVT_BUTTON, self.inputfile_fun)
self.Show()
print(self.filelist_dict)
def inputfile_fun(self,event):
# print(self.choose_filepath_box.GetValue())
files = "EXCEL工作簿(*.xlsx)|*.xlsx|" "EXCEL工作簿(*.xls)|*.xls"
file_dir = wx.FileDialog(None, message="选择单个文件", wildcard=files, style=wx.FD_OPEN) # 弹出的选择框
if file_dir.ShowModal() == wx.ID_OK: # wx.ID_OK是判断结果,并执行相应程序
self.filelist_dict[self.choose_filepath_box.GetValue()] = file_dir.GetPath()
print(self.filelist_dict)
def check_filelist_fun(self, event):
self.check_filelist_bt.Enable(False)
F = Frame_Update(self.check_filelist_bt, filepath_list=self.filelist_dict, call=self.Callback_value)#另外的Frame2,使用函数调用Frame2的值
def Callback_value(self, value):通过call函数进行赋值
self.filelist_dict = value
print(self.filelist_dict)
class Frame_Update(wx.Frame):
def __init__(self, outputbt, filepath_list, call):
wx.Frame.__init__(self, None, -1, 'xxxxx', size=(580, 540),
style=wx.CAPTION | wx.MINIMIZE_BOX | wx.CLOSE_BOX | wx.SYSTEM_MENU |wx.STAY_ON_TOP
)
self.outputbt = outputbt
self.filepath_list = filepath_list
self.call = call
self.panel = wx.Panel(self, -1)
vbox = wx.GridBagSizer(11, 2)
self.filepath_list='000000xxxxxxxx'
def On_Close(self, event):#我绑定了在关闭Frame2的时候值的传递
self.call(self.filepath_list)
self.Destroy()