想在tkinter子窗口中对改子窗口中的变量进行操作,结果是cannot access free variable 'Label1' where it is not associated with a value in enclosing scope
Label1标签是在函数wicket_change()里创建的,所以在look里不能直接调用,解决方法有二:
1)把Label1定义为全局变量:global Label1
2)把Label2作为参数传入look函数:chaxun = Button(command = lambda :look(Label1))
但是除此之外,你这代码还存在两个基本问题:
1)command里的look不能加小括号
2)Label1定义了标签后,直接使用了place(),导致Label1为None,不能使用。要把place()分开来。
改为self.Label1
除非Label1是个全局变量你才可以这样用