首页 > 解决方案 > 为什么我的 tkinter 标签会出现“未知选项“-Text””?

问题描述

我正在尝试使用 Python 创建登录窗口。不幸的是,我在创建登录框架时出错。顺便说一句,我对python很陌生。

当我尝试运行它时,这是显示的错误。

"D:\Project\Python Sample\Scripts\python.exe" "D:/Project/La Solei/Main.py"
Traceback (most recent call last):

  File "D:/Project/La Solei/Main.py", line 23, in <module>
    obj= Login(root)

  File "D:/Project/La Solei/Main.py", line 19, in __init__
    title=Label(Frame_login, Text="Login Here", font=("Impact", 35, "bold"), fg="#CD853F", bg="White").place(x=90,y=30)

  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\tkinter\__init__.py", line 2766, in __init__
    Widget.__init__(self, master, 'label', cnf, kw)

  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\tkinter\__init__.py", line 2299, in __init__
    (widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: unknown option "-Text"

Process finished with exit code 1
from tkinter import *
from PIL import ImageTk
class Login:
   def __init__(self, root):
       self.root = root
       self.root.title("LaSolieSystem")
       self.root.geometry("1199x700+100+50")
       self.root.resizable(False, False)

       #Background
       self.bg=ImageTk.PhotoImage(file="images/Main_image.jpg")
       self.bg_image=Label(self.root, image=self.bg).place(x=0, y=0, relwidth=1, relheight=1)

       #Loginframe
       Frame_login = Frame(self.root, bg="#FFDB58")
       Frame_login.place(x=600, y=50, width=500, height=600)

       #Title & Subtitle
       title=Label(Frame_login, Text="Login Here", font=("Impact", 35, "bold"), fg="#CD853F", bg="White").place(x=90,y=30)


root = Tk()
obj= Login(root)
root.mainloop()

标签: pythontkinter

解决方案


python中的参数名称通常以小写字母开头。您需要在标签参数中更改Text=...为。text=...

title = Label(Frame_login, text="Login Here", font=("Impact", 35, "bold"), fg="#CD853F", bg="White").place(x=90,y=30)

https://docs.python.org/3/library/tkinter.ttk.html#label-options


推荐阅读