![]() |
"tkinter.TclError: NULL main window" - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: "tkinter.TclError: NULL main window" (/thread-32350.html) |
"tkinter.TclError: NULL main window" - Rama02 - Feb-04-2021 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: Does anyone have a solution to this problem because it's been bugging me for over 2 days now.
RE: "tkinter.TclError: NULL main window" - deanhystad - Feb-04-2021 You cannot call Tk() twice. If you need two windows use TopLevel() to make the second window. Tk() doesn't just make a window, it also does a bunch of initialization that is only supposed to happen once. |