Bottom Page

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.
steve_shambles likes this post
Quote
#2
You forgot to pack the label.

def gamestart(): #Starts the game
    lbl = Label(window, text="itworked")
    lbl.pack()
Quote
#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")
   
steve_shambles likes this post
Quote
#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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Tkinter] button command tkinter Heyjoe 6 1,177 Jul-30-2020, 07:06 PM
Last Post: deanhystad
  [tkinter] color change for hovering over button teacher 4 351 Jul-04-2020, 06:33 AM
Last Post: teacher
  tkinter button help Gina92 10 552 May-27-2020, 08:17 AM
Last Post: Gina92
  How to make button text bold in Tkinter? scratchmyhead 2 437 May-16-2020, 02:53 AM
Last Post: scratchmyhead
  Closing window on button click not working kenwatts275 4 357 May-03-2020, 01:59 PM
Last Post: deanhystad
  [Tkinter] Is it possible to automate button generation in tkinter? FirePepi 3 430 Apr-10-2020, 12:14 PM
Last Post: Riddle
  Tkinter:Unable to bind and unbind function with a button shallanq 2 513 Mar-28-2020, 02:05 AM
Last Post: joe_momma
  Returning a value from a tkinter.button call markr0804 4 2,373 Feb-16-2020, 10:35 AM
Last Post: markr0804
  Problem with Submit button Tkinter Reldaing 2 500 Jan-05-2020, 01:58 AM
Last Post: balenaucigasa
  [Tkinter] Mouse click event not working on multiple tkinter window evrydaywannabe 2 861 Dec-16-2019, 04:47 AM
Last Post: woooee

Forum Jump:


Users browsing this thread: 1 Guest(s)