I am assuming that you are using python 3. This is allbecause there are changes in the python 3.
Here is my code that will allow you to decide window size as par your requirement. also maintain those indentation :
from tkinter import *
import tkinter.messagebox
gui = Tk(className='Python Examples - Window Size')
# set window size
#gui.geometry("300x300")
ak: bool = tkinter.messagebox.askyesno("Difficulty", "Would you like to play the easy version?")
if ak:
a = 200
b = 200
gui.geometry('%dx%d' % (a, b))
else:
ka = tkinter.messagebox.askyesno("Difficulty", "Would you like to play a harder version?")
if ka:
a = 400
b = 400
gui.geometry('%dx%d' % (a, b))
else:
akk = tkinter.messagebox.showinfo("Difficulty", "Looks like you will play the harder version after all.")
a = 600
b = 600
gui.geometry('%dx%d' % (a, b))
gui.mainloop()
Another way, where the window will close and open the game window as you want:
import tkinter as tk
def easy():
mw.destroy()
gui = tk.Tk(className='Python Examples - Window Size')
a = 200
b = 200
gui.geometry('%dx%d' % (a, b))
gui.mainloop()
def harder():
mw.destroy()
gui = tk.Tk(className='Python Examples - Window Size')
a = 400
b = 400
gui.geometry('%dx%d' % (a, b))
gui.mainloop()
def tough():
mw.destroy()
gui = tk.Tk(className='Python Examples - Window Size')
a = 600
b = 600
gui.geometry('%dx%d' % (a, b))
gui.mainloop()
mw = tk.Tk()
#If you have a large number of widgets, like it looks like you will for your
#game you can specify the attributes for all widgets simply like this.
mw.option_add("*Button.Background", "white")
mw.option_add("*Button.Foreground", "black")
mw.title('The game')
#You can set the geometry attribute to change the root windows size
mw.geometry("200x200") #You want the size of the app to be 500x500
mw.resizable(0, 0) #Don't allow resizing in the x or y direction
back = tk.Frame(master=mw,bg='white')
back.pack_propagate(0) #Don't allow the widgets inside to determine the frame's width / height
back.pack(fill=tk.BOTH, expand=1) #Expand the frame to fill the root window
#Changed variables so you don't have these set to None from .pack()
go1 = tk.Button(master=back, text='Easy', command=easy)
go1.pack(side=tk.LEFT)
go2 = tk.Button(master=back, text='Harder', command=harder)
go2.pack(side=tk.LEFT)
go3 = tk.Button(master=back, text='Tough', command=tough)
go3.pack(side=tk.LEFT)
close = tk.Button(master=back, text='Quit', command=mw.destroy)
close.pack(side=tk.LEFT)
mw.mainloop()
Get Answers For Free
Most questions answered within 1 hours.