class myApp(tk.Tk):
def __init__(self) -> None:
super().__init__()
self.title("Title of App")
self.geometry("450x400+450+150")
self.create_ui()
def create_ui(self) -> None:
# menu
= tk.Menu(self)
menubar self.config(menu=menubar)
# submenus cascading
= tk.Menu(menubar)
file_menu ="test", command=partial(self.a_comm, text_content="File menu"))
file_menu.add_command(label
= tk.Menu(menubar)
conf_menu ="test", command=partial(self.a_comm, text_content="Config menu"))
conf_menu.add_command(label
='File', menu=file_menu)
menubar.add_cascade(label='Config', menu=conf_menu)
menubar.add_cascade(label
# frame
= ttk.Frame(self)
frame =tk.BOTH, expand=1)
frame.pack(fill
# button
= ttk.Button(frame, text="Test", command=partial(self.a_comm, text_content="Button"))
test_button ="e", padx=5, pady=5)
test_button.pack(anchor
# text
self.text = tk.Text(frame)
self.text.pack(fill=tk.BOTH, expand=1)
if messagebox.askquestion("Title", "Yes or No?", icon="warning",) == "yes":
self.a_comm("YES!!")
else:
self.a_comm("NO MAN!! "*3)
def a_comm(self, text_content: str) -> None:
self.text.insert(tk.END, text_content+"\n")
TkInter
A popular GUI package
Testing tkinter
A simple GUI that just enters lines of text related to the activated widget.
Then run the app
= myApp()
app app.mainloop()