I am trying to create a quiz game but cannot get the labels to be in the right place, I want 'Maths Category' to be in the top left, but when I select the row and column 0 it puts it in the middle? help....................................................................................................................................
import tkinter
import tkinter as tk
from tkinter.ttk import *
from tkinter import *
score = 0
class SampleApp(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self._frame = None
self.switch_frame(MainMenu)
def switch_frame(self, frame_class):
new_frame = frame_class(self)
if self._frame is not None:
self._frame.destroy()
self._frame = new_frame
self._frame.pack()
class MainMenu(tk.Frame):
def __init__(self, master):
#Maths Picture/Button
global photo
tk.Frame.__init__(self, master)
#configure = tk.Frame(self)
#configure.grid_rowconfigure(0, weight=1)
#configure.grid_columnconfigure(0, weight=1)
photo = PhotoImage(file = "MathsPicture.png")
photoimage = photo.subsample(3,3)
lbl = tk.Label(self, text="MainMenu", font=('Verdana', 40, "bold"))
lbl.grid(row=0, column=1)
button = tk.Button(self, image = photo, command=lambda:[master.switch_frame(PageOne), ScoreUpdate()])
button.grid(row=1, column=1)
#tk.Button(self, text="Go to page two",command=lambda:[master.switch_frame(PageTwo), ScoreUpdate()]).pack()
def ScoreUpdate(event=None):
global score
score += 500
class PageOne(tk.Frame):
global score
def __init__(self, master):
tk.Frame.__init__(self, master)
tk.Frame.configure(self,bg='red')
#tk.Frame.configure
tk.Frame.grid_propagate(self)
lbl = tk.Label(self, text="Maths Category", font=("Verdana", 20))
lbl.grid(row=0, column = 0)
lbl = tk.Label(self, text=score , font=("Verdana", 40, "bold"))
lbl.grid(row=1, column=0)
lbl = tk.Label(self, text="Question 1", font=('Helvetica', 18, "bold"))
lbl.grid(row=1, column=3)
btn = tk.Button(self, text="Go back to MainMenu", font=('Helvetica', 20), command=lambda: master.switch_frame(MainMenu))
btn.grid(row=0, column=4)
btn = tk.Button(self, text='Update score', command=ScoreUpdate)
btn.grid(row=3, column=4)
btn = tk.Button(self, text="Go to page two",command=lambda:[master.switch_frame(PageTwo), ScoreUpdate()])
btn.grid(row=4,column=3)
print("Physics Question 1")
class PageTwo(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
tk.Frame.configure(self,bg='red')
tk.Label(self, text="Question 2", font=('Helvetica', 18, "bold")).pack(side="top", fill="x", pady=5)
tk.Button(self, text="Go back to start page",command=lambda: master.switch_frame(PageThree)).pack()
tk.Button(self, text='Update score', command=ScoreUpdate)
print("Physics Question 2")
class PageThree(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
tk.Frame.configure(self,bg='red')
tk.Label(self, text="Question 3", font=('Helvetica', 18, "bold")).pack(side="top", fill="x", pady=5)
tk.Button(self, text="Go back to start page",command=lambda: master.switch_frame(MainMenu)).pack()
tk.Button(self, text='Update score', command=ScoreUpdate)
print("Physics Question 3")
if __name__ == "__main__":
window = SampleApp()
window.geometry("1200x900")
window.mainloop()