Home > OS >  _tkinter.TclError: unknown option "-font"
_tkinter.TclError: unknown option "-font"

Time:06-29

I got "_tkinter.TclError: unknown option "-font"" error from this code. Everything in this code work collectedly except "font=("Arial", 25)". (I use Python3 on VSCode on macOS.)

def openMAINMENUPASSWORD():
    rt = Window.root

    text1 = tk.Label(rt, text="Hello World")
    text1.place(in_=f1, width=210, height=33, relx=0.5,rely=0.50, anchor=tk.CENTER, font=("Arial", 25))
    e1 = tk.Entry(bd=1)
    e1.place(in_=f1, width=210, height=33, relx=0.5,
             rely=0.55, anchor=tk.CENTER, font=("Arial", 25))

    rt.mainloop()

How to deal with this error? Thank you for your reply.

CodePudding user response:

text1 = tk.Label(rt, text="Hello World")
text1.place(in_=f1, width=210, height=33, relx=0.5,rely=0.50, anchor=tk.CENTER, font=("Arial", 25))

font should not be placed in this bracket, it should be placed in [tk.label()][1] and [tk.Entry()][1].

CodePudding user response:

font option should be specified in tk.Label(...) and tk.Entry(...) instead:

def openMAINMENUPASSWORD():
    rt = Window.root

    text1 = tk.Label(rt, text="Hello World", font=("Arial", 25))
    text1.place(in_=f1, width=210, height=33, relx=0.5,rely=0.50, anchor=tk.CENTER)
    e1 = tk.Entry(bd=1, font=("Arial", 25))
    e1.place(in_=f1, width=210, height=33, relx=0.5, rely=0.55, anchor=tk.CENTER)

    rt.mainloop()
  • Related