Python Forum
[Tkinter] What is this error?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] What is this error?
#1
Script,
from tkinter import *

main = Tk()
main.title("1. Unit & Dimentions")
#root.geometry("1600x800+0+0")

#Var Details
length = ["meter", "m", "fundamentals"]
mass = ["kilogram", "kg", "fundamentals"]
time = ["second", "s", "fundamentals"]
current = ["ampere", "A", "fundamentals"]
temperature = ["kelvin", "K", "fundamentals"]
amount_of_substance = ["mole", "mol", "fundamentals"]
luminous_intensity = ["candela", "cd", "fundamentals"]

Fundamentals = [length, mass, time, current, temperature, amount_of_substance, luminous_intensity]

#Text
name = Label(main, text = "1. Unit & Dimentions", font = ("arial", 45, "bold"), fg = "Steel Blue", bd = 10)
mj = Label(main, text = "A product of MihiraJ.com", font = ("arial", 26, "bold"), fg = "#cc5c54", bd = 10)
dev = Label(main, text = "Devloped by Oshadha Mihiranga", font = ("arial", 18, "bold"), fg = "Steel Blue", bd = 10)
search = Label(main, text = "Search", font = ("arial", 10, "bold"), fg = "black", bd = 10)
result_lbl = Label()

#Text boxes
search_box = Entry(main, borderwidth = 4, width = 34)

#Frames
results = LabelFrame(main, text = "Results")
rel_results = LabelFrame(main, text = "Related Results")

#errors
err001 = Label(results, text = "Err001 : Result not Found, Please type again.", fg = "#eb0000")

#functions
def no_input():
    err001.pack(padx = 6, pady = 6, side = LEFT)
    search_box.delete(0, END)

def result_found(name, result):
        search_box.delete(0, END)
        result_lbl.config(results, text = "Physical quantity :  " + name + "\nUnit :  " + result[0] + "\nSymbol :  " + result[1], justify = LEFT)

def search_start(txt_2_search):
    if txt_2_search == "":
        no_input()
    if txt_2_search == "mass":
        result_found("Mass", mass)


#buttons
search_button = Button(main, text = "Start Search", command = lambda : search_start(search_box.get().lower()))

#pack
name.pack()
mj.pack()
search.pack()
search_box.pack()
search_button.pack()
results.pack(fill = X)
result_lbl.pack(padx = 6, pady = 6, side = LEFT)
dev.pack()

mainloop()
Error:
Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1885, in __call__ return self.func(*args) File "D:\3. My folder\Projects\Programing\Python\4. MihiraJ Projects\1. Unit And Dimentions.py", line 52, in <lambda> search_button = Button(main, text = "Start Search", command = lambda : search_start(search_box.get().lower())) File "D:\3. My folder\Projects\Programing\Python\4. MihiraJ Projects\1. Unit And Dimentions.py", line 48, in search_start result_found("Mass", mass) File "D:\3. My folder\Projects\Programing\Python\4. MihiraJ Projects\1. Unit And Dimentions.py", line 42, in result_found result_lbl.config(results, text = "Physical quantity : " + name + "\nUnit : " + result[0] + "\nSymbol : " + result[1], justify = LEFT) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1639, in configure return self._configure('configure', cnf, kw) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1629, in _configure self.tk.call(_flatten((self._w, cmd)) + self._options(cnf)) _tkinter.TclError: unknown option "-class"
What is this error?
It makes no sense to me!
Reply
#2
I don't get an error when I run your code. It doesn't do anything interesting when the search button is pressed. but there is no error.

You cannot set a widget's parent using the config command.
result_lbl = Label()
result_lbl.config(results, text = "Physical quantity")
You need to specify the parent when you create the widget.
results = LabelFrame(main, text = "Results")
result_lbl = Label(results)
If you want to hide or pop up a widget inside a window you can use pack and forget.
Oshadha likes this post
Reply


Forum Jump:

User Panel Messages

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