Hi, I am creating a quiz as part of an assignment that is set for my course work. Here is my actual code for the quiz:
global score import tkinter as tk from tkinter import* from tkinter import ttk from tkinter import messagebox root=Tk() notebook=ttk.Notebook(root) frame1=ttk.Frame(notebook) frame2=ttk.Frame(notebook) frame3=ttk.Frame(notebook) notebook.add(frame1,text="Q1A,Q1B,Q1C,Q1D") notebook.add(frame2,text="Q2") notebook.add(frame3,text="Q3") quiz=Tk() quiz.geometry("500x700") quiz.title("Quiz Code") quiz.resizable(False,False) score=0 welcome=tk.Label(quiz,text="Welcome to Quiz") welcome.pack() def Inst(): t=tk.Label(quiz,text="All you have to do is answer each question with either a 'A, B, C, D' or the actual word") t.pack() def Start(): Question1=ttk.Label(frame1,text='Q.1.Which anime is Hinata Hyuga from?') Question1.grid(row=1,column=0, sticky=W) var=StringVar() Q1A=ttk.Radiobutton(frame1,text='[A] Watashi ni tenshi ga maiorita',variable=var,value='False1') Q1A.grid(row=2,column=0,sticky=W) Q1B=ttk.Radiobutton(frame1,text='[B] Oregairu',variable=var,value='False2') Q1B.grid(row=3,column=0,sticky=W) Q1C=ttk.Radiobutton(frame1,text='[C] Naruto',variable=var,value='True') Q1C.grid(row=4,column=0,sticky=W) Q1D=ttk.Radiobutton(frame1,text='[D] Overlord', variable=var, value='False3') Q1D.grid(row=5,column=0,sticky=W) submit=ttk.Button(frame1,text='Submit',command=Answer) submit.grid() def Answer(): if var.get() == 'True': messagebox.showinfo('Congratulations!', message='You have got the answer right!Score is {}'.format(score)) else: messagebox.showinfo('Oops!', message='You have got the answer wrong!') startButton=tk.Button(quiz,bg="green",fg="black",command=Start,text="Start") startButton.pack() instr=tk.Button(quiz,bg="grey",fg="black",command=Inst,text="User Instructions") instr.pack() end=tk.Button(quiz,text="Exit",command=quiz.destroy) end.pack() quiz.mainloop()Whenever I try to run my quiz & click on the, I always keep on getting a TCL error stating "NULL main window" Here is the error:
Error:Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Ramaz\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1884, in __call__
return self.func(*args)
File "C:\Users\Ramaz\OneDrive\Documents\Mustafa Work\Quiz code.py", line 35, in Start
Question1=ttk.Label(frame1,text='Q.1.Which anime is Hinata Hyuga from?')
File "C:\Users\Ramaz\AppData\Local\Programs\Python\Python39\lib\tkinter\ttk.py", line 759, in __init__
Widget.__init__(self, master, "ttk::label", kw)
File "C:\Users\Ramaz\AppData\Local\Programs\Python\Python39\lib\tkinter\ttk.py", line 557, in __init__
tkinter.Widget.__init__(self, master, widgetname, kw=kw)
File "C:\Users\Ramaz\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2568, in __init__
self.tk.call(
_tkinter.TclError: NULL main window
Does anyone have a solution to this problem because it's been bugging me for over 2 days now.
buran write Feb-04-2021, 05:47 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.