Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Why Do I Get The _tkinter.TclError: unknown option "-font" Error Showing Up In My GUI Program?

$
0
0

I write this code:

from tkinter import * # Import most of tkinter functions from tkinter import messagebox # Import tkinter message box functionfrom tkinter import colorchooser # Import Tkinter colour chooserfrom tkinter.ttk import * # Import Tkinter Progress barimport time# Widgets         = GUI elements: buttons, textboxes, labels, images # Windows         = Serves as a container to hold these widgets # Labels          = An area widget that holds text and/or an image within a window# Entry Widget    = A Textbox that accepts a single line of user input# Radio boxes     = Similiar to checkbox but only one can be chosen# Listbox         = A listing of selectable text items from it's own containercount = 0File_Start = "C:\\Users\\User\\Desktop\\Python Projects\\Python Photos\\"def Add_Food():    List_Box_Of_Food.insert(List_Box_Of_Food.size(),Food_Add_EnterBox.get())    Food_Add_EnterBox.delete(0,END)def Submit_Food():     print("You have ordered "+List_Box_Of_Food.get(List_Box_Of_Food.curselection()))def Submit_Temp():    print("The tempature is "+str(Temp_Scale.get())+" Degrees C")def Pick_Celeb():     selected_index = z.get()    print("You picked" + Celeb_Names[selected_index])  def click_button():     global count     count += 1    print("You have clicked the button "+str(count)+" Times")def Submit_Username():    Username = Enter_Box.get()     print("You have set your username to: "+Username)    delete()    Enter_Box.config(state=DISABLED)def delete():     Enter_Box.delete(0,END)def backspace():     Enter_Box.delete(len(Enter_Box.get())-1,END)def display():    if (Check_Button_Status.get()==1):         print("You agree")    else:         print("You don't agree")def Click_Username_Box(event):        Enter_Box.delete(0,END) def Click_Food_Box(event):        Food_Add_EnterBox.delete(0,END)def Click_Message_Box_Button():     messagebox.showinfo(title="Even more ultimate GUI!",                        message="You have found the even more ultimate GUI!")    #messagebox.warning - (Shows an error symbol)    #messagebox.error -   (Shows a warning symbol)    #messagebox.ask -     (Makes an enter box with it's appilications depending on what is put after ask)def Click_Colour_Button():     User_Chosen_Colour = colorchooser.askcolor()    User_Chosen_Colour_HexValue = User_Chosen_Colour[1] # We pick index value 0 because the RGB info of the colour is index 0 and the hex value of the colour is in index 1    print("You picked "+User_Chosen_Colour_HexValue)    Window.config(bg=User_Chosen_Colour_HexValue)def Reset_Colour():     Window.config(bg="#ffffff")def Start_Weather_Check():    Tasks_Needed_Execute = 10    for ProgressIndex in range(Tasks_Needed_Execute):         time.sleep(1)        Weather_Bar["value"]+=10Window = Tk() # Instaniates an instance of a window z = IntVar(value=-1)Elon_Musk_Photo = PhotoImage(file=File_Start+"Elon_Musk(50x28).png")Jeff_Bezoz_Photo = PhotoImage(file=File_Start+"Jeff_Bezoz(50x28).png")Mark_Zuckerberg_Photo = PhotoImage(file=File_Start+"Mark_Zuckerberg_Small(50x30).png")Fire_Flame_Image = PhotoImage(file=File_Start+"FireFlame(50x50).png")Snowflake_Image = PhotoImage(file=File_Start+"Snowflake(50x50).png")Celeb_Photos = [Elon_Musk_Photo, Jeff_Bezoz_Photo, Mark_Zuckerberg_Photo]Celeb_Names = ["Elon Musk", "Jeff Bezoz", "Mark Zuckerberg"]for Index in range(len(Celeb_Names)):    radiobutton = Radiobutton(Window,                              text=Celeb_Names[Index], # Adds text to radio buttons                              variable=z, # Groups radio buttons together if they have the same variable                              value=Index,  # Assigns each single radio button a numerical value                              font=("Impact",20),                              image=Celeb_Photos[Index],                              compound="right",                              width=250,                              command=Pick_Celeb)     radiobutton.place(x=500, y=50+Index*45)Photo = PhotoImage(file=File_Start+"Pig2.png") # Converts an regular image into one tkinter can useLike_Button = PhotoImage(file=File_Start+"Like-Button2.png")Window.geometry("900x750") # Changes the dimensions of the WindowWindow.title("The Ultimate GUI Program") # Changes the title of the WindowWindow.iconbitmap(File_Start+"AngryBird9.ico") # Set icon of the window.button = Button(Window,                text="Click me",                command=click_button,                font=("Comic Sans,",10,"bold"),                fg="Red",                bg="black",                activeforeground="Red", # Activeforeground and activebackground is used to make it so the button does not change colour when pressed                activebackground="black",                image=Like_Button,                compound="bottom") #- Makes it so the button is behind items on it. - This allows the text to be shown and not be covered by the buttonbutton.place(x=50,y=50) # Places the button at x coordinate 50 and at y coordinate 50Window.config(background="white") # Sets the background colour#Adding an image and text onto the Window: Pig_Label = Label(Window,                                       # Creates a label              text="You are using the best program ever!",               font=("Arial",10,"bold"),              fg="red",              bg="white",relief=RAISED,bd=10,              padx=10,              pady=10,image=Photo,              compound="bottom")Pig_Label.place(x=170,y=170) # Placing the image in a specifed place Enter_Box = Entry(Window,font=("Arial"),fg="Black",bg="Gray") Enter_Box.place(x=460,y=220)Submit_button = Button(Window,        # Creates a Button that can submit text into a variable                       text="Submit",                       command=Submit_Username)Submit_button.place(x=700,y=220)Delete_button = Button(Window,       # Creates a Button that can delete all the text inside the entry box                       text="Delete",                       command=delete)Delete_button.place(x=750,y=220)BackSpace_button = Button(Window,    # Creates a Button that deletes the most recent character                          text="Backspace",                          command=backspace)BackSpace_button.place(x=795,y=220)  # Places the backspace button at x = 795 and y = 220Check_Button_Status = IntVar()Checkbox = Checkbutton(Window,       # Creates a checkbox with text inside                         text="I agree to the TOS",                       variable=Check_Button_Status,                       onvalue=1,                       offvalue=0,                       command=display)Checkbox.place(x=200,y=100) # Places the checkbox at x = 200 and y = 100Temp_Scale = Scale(Window,                   from_=100,to=0, # Sets the highest and lowest value of the scale                   length=250,                   font=("Consolas",13),                   tickinterval=20, # The step for numbers displayed on the side of the scale                   orient="vertical", # Sets the direction in which the scale goes                   resolution=0.5, # The increment of the slider values                   troughcolor="red", # Sets the colour of the user controlled sliding part                   bg="gray",                   fg="white") Temp_Submit_Button = Button(Window,                            text="Submit tempature",                            command=Submit_Temp)Temp_Scale.set((Temp_Scale["from"]-Temp_Scale["to"])/2) # Sets the starting value for the scale (The value the scale will be on without user input). It is calculated to allow it to work if the range is changedHot_Label = Label(image=Fire_Flame_Image)Cold_Label = Label(image=Snowflake_Image)Hot_Label.place(x=500,y=298)Cold_Label.place(x=500,y=605)Temp_Submit_Button.place(x=590,y=350)Temp_Scale.place(x=480,y=350)List_Box_Of_Food = Listbox(Window,                           bg="#f7ffde",                           font="Constantia",)List_Of_Food = ["Pizza","Hotdog","Apple","Ham Sandwich"]for FoodIndex in range(len(List_Of_Food)):     List_Box_Of_Food.insert(FoodIndex,List_Of_Food[FoodIndex])List_Box_Of_Food.place(x=150,y=440)Food_Submit_Button = Button(Window,                            text="Submit Food",                            command=Submit_Food)Food_Add_Button = Button(Window,                            text="Add Food",                            command=Add_Food)Food_Add_EnterBox = Entry(Window)Food_Add_EnterBox.insert(0,"Enter food")Food_Add_EnterBox.bind("<Button-1>",Click_Food_Box)Food_Add_EnterBox.place(x=20, y=480)Food_Submit_Button.place(x=20, y=440)Food_Add_Button.place(x=20, y=520)Enter_Box.insert(0,"Enter username") # Puts text inside the entry box (As a place holder in this example)Enter_Box.bind("<Button-1>",Click_Username_Box) # Removes the textMessage_Box_Button = Button(Window,                            text="Display a new window",                            command=Click_Message_Box_Button)Message_Box_Button.place(x=650, y=650)Colour_Chooser_Button = Button(Window,                               text="Press me to change the colour of this window",                               command=Click_Colour_Button)Colour_Chooser_Button.place(x=650, y=620)Rest_Colour_Button = Button(Window,                            text="Reset colour",                            command=Reset_Colour)Rest_Colour_Button.place(x=650, y=680)Check_The_Weather_Outside_Button = Button(Window,                                          text="Check the weather outside",                                          command=Start_Weather_Check)Check_The_Weather_Outside_Button.place(x=100,y=200)Weather_Bar = Progressbar(Window)Weather_Bar.place(x=100,y=150)Window.mainloop() # - Displays the window on the computer screen 

But I get this error when trying to run the code:

Traceback (most recent call last):File "c:\Users\User\Desktop\Python Projects\3GUI.py", line 100, in radiobutton = Radiobutton(Window,^^^^^^^^^^^^^^^^^^^File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\tkinter\ttk.py", line 1022, in initWidget.init(self, master, "ttk::radiobutton", kw)File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\tkinter\ttk.py", line 527, in inittkinter.Widget.init(self, master, widgetname, kw=kw)File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\tkinter_init_.py", line 2648, in initself.tk.call(_tkinter.TclError: unknown option "-font"

And whenever I try to fix by removing the unknown option it keeps just saying there is a new unknown option and it seems like it would happen until there are no items left on the GUI at all.

I would of cut down the code to a spefic part however I don't where the error is, all I know is that where it says the unknown option is on line 100.


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>