I have an idea to create a simple scoreboard app (sport) with two windows (creating in Tkinter). One is for controlling and another one for output information.
So the idea is that I press button "show scoreboard" in a tk.Toplevel window and it appears in the main app window. And as I press hide, it hides. I know that I can create it just writing script without Classes and just like hundreds def strings but I want to use OOP as I would like to start programming the right way.
My problem is that when I press "Hide the scoreboard" (I create Labels for scoreboard) label is not hiding. Any suggestions?
I know that commands and defs must be in the same "tree", but how to arrange it when using the OOP.
So here is my code
import tkinter as tk
def forget():
scoreboard.pack_forget()
class Main(tk.Tk):
def __init__(self):
super().__init__()
self.title("Scorebug")
self.geometry("500x300")
self.configure(background="green")
scoreboard = tk.Label(self, text="This is like scoreboard")
scoreboard.pack()
class Control(tk.Toplevel):
def __init__(self):
super().__init__()
self.title("Controls")
self.geometry("100x300")
self.configure(background="red")
hidelabels = tk.Button(self, text="Hide the scoreboard", command=forget)
hidelabels.pack()
app = Main()
ctr = Control()
ctr.mainloop()
app.mainloop()