python - 为什么我的 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()
解决方案
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
推荐阅读
- python - 如何让 Python 程序再次执行自身?
- concourse - 无法在大厅触发工作
- java - Java 安全策略文件是否支持注释?
- vb.net - 自动更新 ID 标签
- node.js - node.js Azure Web App 在长 url 上返回 400
- sql - CASE WHEN NOT 不会产生正确的结果?
- c# - 带有 ResponseHeadersRead 的 HttpClient 在没有 Fiddler 的情况下第二次 GetAsync 尝试失败(超时)(Http/Https 调试器)
- sql - SQL查询及疑难解答
- python - 停止 wxPython 循环
- r - Rmd 笔记本中节号后的尾随句点