Python Forum
"tkinter.TclError: NULL main window"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"tkinter.TclError: NULL main window"
#1
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.
Reply


Messages In This Thread
"tkinter.TclError: NULL main window" - by Rama02 - Feb-04-2021, 05:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 341 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Tkinter multiple windows in the same window tomro91 1 786 Oct-30-2023, 02:59 PM
Last Post: Larz60+
Exclamation [Tkinter] Error when closing the main window with destroy TomasSanchexx 1 727 Aug-06-2023, 01:54 AM
Last Post: deanhystad
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,374 May-25-2023, 07:37 PM
Last Post: deanhystad
  tkinter.TclError: can't invoke "canvas" command cybertooth 8 5,774 Feb-23-2023, 06:58 PM
Last Post: deanhystad
  [Tkinter] tkinter.TclError: expected integer but got " " TWB 2 3,524 Feb-19-2023, 05:11 PM
Last Post: TWB
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 1,830 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  [Tkinter] Background inactivity timer when tkinter window is not active DBox 4 2,862 Apr-16-2022, 04:04 PM
Last Post: DBox
  why my list changes to a string as I move to another window in tkinter? pymn 4 2,546 Feb-17-2022, 07:02 AM
Last Post: pymn
  main lop in python tkinter barryjo 6 5,056 Jan-24-2022, 03:09 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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