Python Forum

Full Version: Checking button click in Tkinter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
You forgot to pack the label.

def gamestart(): #Starts the game
    lbl = Label(window, text="itworked")
    lbl.pack()
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]
(Oct-19-2019, 07:54 AM)Larz60+ Wrote: [ -> ]it's cleaner to use a message box,
here's a simple working example:
import tkinter.messagebox as tm

tm.showinfo("gamestart","It worked")

That was a placeholder