Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] GUI
#1
Hello, im creating a code for main menu for a game. Im using tkinter and want to make my buttons open a new window and so on . Basically making my buttons do something when pressed. any answers?

from tkinter import *

def main_screen():
screen= Tk()
screen.geometry("300x250")
screen.title("Bomberman")
Label(text = "Bomberman", bg = "grey", font = ("Arial", 13)).pack()
Button(text = "START").pack()
Label(text = "").pack()
Button(text = "LEADERBOARDS").pack()
screen.mainloop()

if __name__ == '__main__':
main_screen()

you absoilute snakes wtf you doing reply im in a computer science lesson and youre longing man out
Reply
#2
define buttons as so:
def myfunction():
    ...

Button(text = "START", command=myfunction).pack()
I prefer to name buttons, and include pack, grid, place on separate line (most often grid)
Reply
#3
Thankyou sir. what do i put inside the function to make it so when i click a button it opens a new window
Reply
#4
There are many examples (google 'tkinter create new window on button click')
for example: https://abdurrahmaanjanhangeer.wordpress...nt-page-1/
Reply


Forum Jump:

User Panel Messages

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