[Tkinter] Checking button click in Tkinter - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] Checking button click in Tkinter (/thread-21883.html) |
Checking button click in Tkinter - GalaxyCoyote - Oct-19-2019 Good evening everyone, I am trying to make a menu for one of my games. The idea is, you see the start menu you hit the start button then it goes to the main game menu. It seems simple but I have run into complications. NOTE: I am new to Tkinter, I don't know any complicated workarounds, I am so new that you can tell my abilities from the code I have already written (for the most part). As it turns out, the transition from 3+ years of console to GUI is proving to be difficult Here is my code: import tkinter from tkinter import * #Window Setup window = Tk() window.title("WIP NAME") window.geometry("650x400") #Variables Happy = 0 #Counter for the peoples opinion Survival = 0 #Water, Food, etc. Social = 0 #Events Awards = 0 #Simply to keep the player playing #Definitions def mainmenu(): #main menu starttxt = Label(window, text = "WIP NAME") #text starttxt.pack() startbtn = Button(window, text = "START", command = gamestart) #starts the game (I want to check if this is pressed and then proceed to forget the pack if it is) startbtn.pack() def gamestart(): #Starts the game Label(window, text = "itworked") #mainloop mainmenu() window.mainloop()Any pointers in the right direction would be greatly appreciated, thanks in advance. RE: Checking button click in Tkinter - steve_shambles - Oct-19-2019 You forgot to pack the label. def gamestart(): #Starts the game lbl = Label(window, text="itworked") lbl.pack() RE: Checking button click in Tkinter - Larz60+ - Oct-19-2019 it's cleaner to use a message box, here's a simple working example: import tkinter.messagebox as tm tm.showinfo("gamestart","It worked")[attachment=736] RE: Checking button click in Tkinter - GalaxyCoyote - Oct-20-2019 (Oct-19-2019, 07:54 AM)Larz60+ Wrote: it's cleaner to use a message box, That was a placeholder |