python wxpython 不同Frame 之间的参数传递

对于使用触发事件来反应的按钮传递参数如下:

可以通过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()

 

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值