I'm trying to get data from a Toplevel window with Tkinter into a full Tk window.
I have my start menu Start.py that contains the class Start. The Start menu has a button which leads to a map editor in another window
self.config_4 = tk.Radiobutton(self.gamemode, text="Custom", value = 4, variable = val, command = self.set_custom)
which leads to
def set_custom(self):
self.editor = Editor(self.menu)
self.board = self.editor.getBoard()
self.board = Board(BoardType.CLASSIC)
Editor is another file that opens a Toplevel window and contains the attribute self.board which I want to receive in Start.py
The destroy function stops the rest of the execution, and quit too. I tried using grab_set and wait for the window but without mainloop the editor does not work properly.
So basically the only thing I want is to get self.board from Editor to Start, and then from Start to main. Both of these is the same destroy problem.
Thanks !
#First.py
import tkinter as tk
from Test import Second
class First:
def __init__(self):
self.window = tk.Tk()
self.test = tk.Button(self.window, command = self.popup, text="Test me").pack()
self.stop = tk.Button(self.window, command = self.window.destroy, text="Quit").pack()
self.window.mainloop()
def popup(self):
a = Second()
self.one = a.get_one()
def get_one(self):
return self.one
if __name__ == '__main__':
var = First()
print(var.get_one())
#######################
#Test.py
import tkinter as tk
class Second:
def __init__(self):
self.popup = tk.Toplevel()
myvar = tk.IntVar()
self.one = tk.Radiobutton(self.popup, text="one", value = 1, variable = myvar, command = self.set_one)
self.two = tk.Radiobutton(self.popup, text="two", value = 2, variable = myvar, command = self.set_two)
self.done = tk.Button(self.popup, command = self.popup.destroy, text = "Bye")
self.one.grid(row = 0, column = 0)
self.two.grid(row = 0, column = 1)
self.done.grid(row = 1, column = 0, columnspan = 2)
def set_one(self):
self.one = "Hi"
def set_two(self):
self.one = "Bye"
def get_one(self):
return self.one