Python Forum
[Tkinter] Checking button click in Tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Checking button click in Tkinter
#1
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.
Reply
#2
You forgot to pack the label.

def gamestart(): #Starts the game
    lbl = Label(window, text="itworked")
    lbl.pack()
Reply
#3
it's cleaner to use a message box,
here's a simple working example:
import tkinter.messagebox as tm

tm.showinfo("gamestart","It worked")
   
Reply
#4
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] TKinter Remove Button Frame Nu2Python 8 820 Jan-16-2024, 06:44 PM
Last Post: rob101
  tkinter - touchscreen, push the button like click the mouse John64 5 746 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,387 May-25-2023, 07:37 PM
Last Post: deanhystad
  Figure Gets Larger Every time I click a show button joshuagreineder 2 1,271 Aug-11-2022, 06:25 AM
Last Post: chinky
  Can't get tkinter button to change color based on changes in data dford 4 3,364 Feb-13-2022, 01:57 PM
Last Post: dford
  Creating a function interrupt button tkinter AnotherSam 2 5,419 Oct-07-2021, 02:56 PM
Last Post: AnotherSam
  [Tkinter] Have tkinter button toggle on and off a continuously running function AnotherSam 5 4,920 Oct-01-2021, 05:00 PM
Last Post: Yoriz
  tkinter showing image in button rwahdan 3 5,524 Jun-16-2021, 06:08 AM
Last Post: Yoriz
  [Tkinter] Modify Class on Button Click KDog 4 3,906 May-11-2021, 08:43 PM
Last Post: KDog
  tkinter button image Nick_tkinter 4 3,964 Mar-04-2021, 11:33 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020