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 showing image in button rwahdan 3 365 Jun-16-2021, 06:08 AM
Last Post: Yoriz
  [Tkinter] Modify Class on Button Click KDog 4 1,432 May-11-2021, 08:43 PM
Last Post: KDog
  tkinter button image Nick_tkinter 4 818 Mar-04-2021, 11:33 PM
Last Post: deanhystad
  tkinter python button position problem Nick_tkinter 3 810 Jan-31-2021, 05:15 AM
Last Post: deanhystad
  TKinter restarting the mainloop when button pressed zazas321 7 2,094 Jan-26-2021, 06:38 AM
Last Post: zazas321
  tkinter touchscreen scrolling - button press makes unwanted scrolling nanok66 1 777 Dec-28-2020, 10:00 PM
Last Post: nanok66
  [Tkinter] Button click problem using OOP JohnB 5 796 Oct-21-2020, 12:43 PM
Last Post: JohnB
  Tkinter - How can I remove the background borders from ttk.Button? TurboC 4 4,698 Oct-18-2020, 10:58 AM
Last Post: TurboC
  tkinter | Button color text on Click Maryan 2 868 Oct-09-2020, 08:56 PM
Last Post: Maryan
  [Tkinter] button command tkinter Heyjoe 6 1,855 Jul-30-2020, 07:06 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