我想通过另一个类传递一个url来显示图片
我试图通过Stringvar传递我的变量(因为这是我所知道的唯一方法),但出现错误PY_VAR3
class pageFunction(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
def meteo(self):
image_url = url <---- This variable I want to pass it to page1
class page1(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
self.controller = controller
img = Image.open(--->I want to put my variable here<---)
self.img = ImageTk.PhotoImage(img)
我想将变量从pageFunction传递给page1
答案 0 :(得分:0)
此处举例说明如何使用kwargs
args = ("Geeks", "for", "Geeks")
myFun(*args)
kwargs = {"arg1" : "Geeks", "arg2" : "for", "arg3" : "Geeks"}
myFun(**kwargs)
就像在您的代码中这样
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
def meteo(self):
for arg in args: ############
image_url = arg ##########
class page1(tk.Frame):
def __init__(self, parent, controller,arg):
tk.Frame.__init__(self,parent)
self.controller = controller
img = Image.open(arg)
self.img = ImageTk.PhotoImage(img)