我有三页纸。一个登录屏幕、一个食堂页面和一个管理页面。当我登录时,我有两个选项:单击一个按钮将我带到餐厅页面,或者单击一个按钮将我带到管理页面。使用按钮打开这些页面是可行的,但是,这些屏幕中的变量将不起作用。
功能全部是在我的食堂和管理页面中选择的所有内容。我不知道为什么当我像这样调用变量时,它们不能工作,但是页面本身是可以工作的。
def CallCanteen():
from practice import All
def CallAdmin():
from Admin import All
if result:
self.master.destroy()
root=Tk()
root.geometry("400x400")
root.title("Canteen System")
Label(text = "welcome to the dashboard").pack()
Button(root, text = "Canteen Page", command=CallCanteen).pack()
Button(root, text = "Admin Page",command=CallAdmin).pack()是的,我试过了:
def CallCanteen():
from practice import *
def CallAdmin():
from Admin import *但这会导致语法错误。
发布于 2020-01-11 18:47:29
您应该将其他模块(在本例中为"Admin“和"practice")中的所有代码放在一个类中。这对你来说很管用。
就像我在这个例子中所做的那样:
Module_1:
import tkinter as tk
def test_func():
from Module_2 import TestClass
root = tk.Tk()
b = tk.Button(root, text="Click", command=lambda: test_func())
b.pack()
root.mainloop()Module_2:
class TestClass:
import tkinter as tk
examle_variable = 0
root = tk.Tk()
lbl = tk.Label(root, text="Test Label")
lbl.pack()
root.mainloop()要访问任何变量,请在其名称之前使用class名称。在本例中:TestClass.example_variable
这对你来说很有用
https://stackoverflow.com/questions/59687044
复制相似问题