Python 使用“问题”;root.attributes(';-type';,';splash';)";在特金特 问题

Python 使用“问题”;root.attributes(';-type';,';splash';)";在特金特 问题,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,我的问题是,我想为我的Tkinter应用程序创建一个自定义标题栏。我不想使用root.overrideredirect(True),因为它会将应用程序从任务栏中删除。因此,我决定使用root.attributes('-type',splash'),但当我运行应用程序时,我遇到了以下错误: \u tkinter.TclError:错误#args:应为“wm属性窗口?-alpha?double?-透明颜色?颜色?-禁用?布尔?-全屏?布尔?-工具窗口?布尔?-最顶端?布尔??” 代码 完全错误 C:

我的问题是,我想为我的Tkinter应用程序创建一个自定义标题栏。我不想使用
root.overrideredirect(True)
,因为它会将应用程序从任务栏中删除。因此,我决定使用
root.attributes('-type',splash')
,但当我运行应用程序时,我遇到了以下错误:
\u tkinter.TclError:错误#args:应为“wm属性窗口?-alpha?double?-透明颜色?颜色?-禁用?布尔?-全屏?布尔?-工具窗口?布尔?-最顶端?布尔??”

代码 完全错误
C:\Users\User\AppData\Local\Programs\Python\Python39\Python.exe C:/Users/User/Desktop/PythonProjects/SideDrawer/main.py
回溯(最近一次呼叫最后一次):
文件“C:\Users\User\Desktop\PythonProjects\SideDrawer\main.py”,第7行,在
属性('type','splash')
wm\U属性中的文件“C:\Users\User\AppData\Local\Programs\Python39\lib\tkinter\\uuuuu init\uuuu.py”,第1976行
返回self.tk.call(args)
_tkinter.TclError:错误#args:应为“wm属性窗口?-alpha?double?-透明颜色?颜色?-禁用?布尔?-全屏?布尔?-工具窗口?布尔?-最顶端?布尔??”
进程已完成,退出代码为1

那么我该如何解决这个问题呢?

这显然意味着没有这样的属性,你必须以某种方式组合两个窗口,以便一个被撤销,另一个被重写。你可以尝试键入
工具窗口
@matiss OP想要一个自定义标题栏,非无边界窗口。@acw1668如何使用toolwindow属性仅限根属性('-toolwindow',True)
from tkinter import *
from tkinter.ttk import Notebook, Style, Separator

# root of app
root = Tk()
root.geometry("800x600")
root.attributes('-type', 'splash')

# style
style = Style()
# background color of separator
style.configure("Line.TSeparator", background="#2C313A")

# icons
icon = PhotoImage(file="icon.png")
menu_icon = PhotoImage(file="menu.png")
close_icon = PhotoImage(file="close.png")
maximize_icon = PhotoImage(file="maximize.png")
minimize_icon = PhotoImage(file="minimize.png")
restore_icon = PhotoImage(file="restore.png")

# make a frame for the title bar
title_bar = Frame(root, bg='#21252B', bd=0)
title_bar.place(relx=0, rely=0, relwidth=1, height=45)

# Close button for title bar
close_button = Button(title_bar, bg='#21252B', bd=0, image=close_icon, command=root.destroy)
close_button.place(relx=0.95, rely=0.35)

# Maximize button for title bar
max_button = Button(title_bar, bg='#21252B', bd=0, image=maximize_icon, command=root.destroy)
max_button.place(relx=0.9, rely=0.275)

# Restore button for title bar
restore_button = Button(title_bar, bg='#21252B', bd=0, image=restore_icon, command=root.destroy)

# Minimize button for title bar
min_button = Button(title_bar, bg='#21252B', bd=0, image=minimize_icon, command=root.destroy)
min_button.place(relx=0.85, rely=0.275)

# Icon for title bar
title_bar_icon = Label(title_bar, image=icon, bg='#21252B')
title_bar_icon.pack(side=LEFT)

# bottom separator for title bar
title_bar_separator = Separator(root, orient="horizontal", style="Line.TSeparator")
title_bar_separator.place(relx=0, rely=0.075, relwidth=1)

root.mainloop()
C:\Users\User\AppData\Local\Programs\Python\Python39\python.exe C:/Users/User/Desktop/PythonProjects/SideDrawer/main.py
Traceback (most recent call last):
  File "C:\Users\User\Desktop\PythonProjects\SideDrawer\main.py", line 7, in <module>
    root.attributes('type', 'splash')
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1976, in wm_attributes
    return self.tk.call(args)
_tkinter.TclError: wrong # args: should be "wm attributes window ?-alpha ?double?? ?-transparentcolor ?color?? ?-disabled ?bool?? ?-fullscreen ?bool?? ?-toolwindow ?bool?? ?-topmost ?bool??"

Process finished with exit code 1