Я хочу вызвать GUI class
в B.py с помощью кнопки Measure
в A.py. Это работает, но я нахожу что-то странное в class B
1. запись не показывает текст «test», который определен self.var_PSA
.
2. Нажимает кнопку PSA
, но содержимое записи тоже не меняется.
Если я запускаю B.py, все функции работают нормально. Как решить проблему?
A.py
import tkinter as tk
import B
class main_win(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self._frame = None
self.show_frame(Page3)
def show_frame(self, frame_class):
new_frame = frame_class(self)
if self._frame is not None:
self._frame.destroy()
self._frame = new_frame
self._frame.pack()
class Page3(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self,master, width=900, height=620, bg = "#d8d8d8")
self.master = master
self.button_meas = tk.Button(self, command = lambda:self.CallB())
self.button_meas.place(relx=0.278, rely=0.5, height=31, width=94)
self.button_meas.configure(activebackground="#ececec")
self.button_meas.configure(activeforeground="#000000")
self.button_meas.configure(background="#d9d9d9")
self.button_meas.configure(disabledforeground="#a3a3a3")
self.button_meas.configure(foreground="#000000")
self.button_meas.configure(highlightbackground="#d9d9d9")
self.button_meas.configure(highlightcolor="black")
self.button_meas.configure(pady="0")
self.button_meas.configure(text='''Measure''')
def CallB(self):
B.GUI()
app = main_win()
app.mainloop()
B.py
import tkinter as tk
class GUI(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
tk.Tk.geometry(self, "1200x820")
self.Frame1 = tk.Frame(self)
self.Frame1.place(relx=0.057, rely=0.147, relheight=0.263
, relwidth=0.895)
self.Frame1.configure(relief='groove')
self.Frame1.configure(borderwidth="2")
self.Frame1.configure(relief="groove")
self.Frame1.configure(background="#d9d9d9")
self.Frame1.configure(highlightbackground="#d9d9d9")
self.Frame1.configure(highlightcolor="black")
self.var_PSA = tk.StringVar()
self.var_PSA.set("test")
self.PSA_Entry = tk.Entry(self.Frame1,textvariable = self.var_PSA)
self.PSA_Entry.place(relx=0.676, rely=0.465, height=31
, relwidth=0.296)
self.PSA_Entry.configure(background="white")
self.PSA_Entry.configure(disabledforeground="#a3a3a3")
self.PSA_Entry.configure(font="TkFixedFont")
self.PSA_Entry.configure(foreground="#000000")
self.PSA_Entry.configure(highlightbackground="#d9d9d9")
self.PSA_Entry.configure(highlightcolor="black")
self.PSA_Entry.configure(insertbackground="black")
self.PSA_Entry.configure(selectbackground="#c4c4c4")
self.PSA_Entry.configure(selectforeground="black")
self.button_PSA = tk.Button(self.Frame1, command = lambda: self.PSA_event())
self.button_PSA.place(relx=0.594, rely=0.465, height=31, width=70)
self.button_PSA.configure(activebackground="#ececec")
self.button_PSA.configure(activeforeground="#000000")
self.button_PSA.configure(background="#d9d9d9")
self.button_PSA.configure(disabledforeground="#a3a3a3")
self.button_PSA.configure(foreground="#000000")
self.button_PSA.configure(highlightbackground="#d9d9d9")
self.button_PSA.configure(highlightcolor="black")
self.button_PSA.configure(pady="0")
self.button_PSA.configure(text='''PSA''')
def PSA_event(self):
self.var_PSA.set("hello")
if __name__ == '__main__':
app = GUI()
app.mainloop()