Tkinter:在顶层使用 ttkthemes window
Tkinter: Using ttkthemes on a Toplevel window
from tkinter import *
import tkinter.ttk as ttk
from tkinter import ttk
from ttkthemes import themed_tk as tk
import sqlite3
from PIL import Image, ImageTk
#Root window configuration
root = tk.ThemedTk()
root.get_themes()
root.set_theme('plastik')
root.geometry("500x500")
root.resizable(height=False, width=False)
def adminlogin_function():
# adminlogin_window configuration
# adminlogin_window = Toplevel()
adminlogin_window = tk.Toplevel()
adminlogin_window.get_themes()
adminlogin_window.set_theme('plastik')
adminlogin_window.geometry("700x400")
# Widgets on adminlogin_window
admin_username_label = Label(adminlogin_window, text="Username", fg="black")
admin_username_label.place(x=388, y=135)
admin_username_entry = Entry(adminlogin_window, border=2)
admin_username_entry.place(x =490 , y =135, width = 85)
admin_pass_label = Label(adminlogin_window, text="Password", fg="black")
admin_pass_label.place(x = 388, y= 180)
admin_pass_entry = Entry(adminlogin_window, border=2,show="*")
admin_pass_entry.place(x =490 , y =180, width = 85)
admin_login_button = Button(adminlogin_window, text="Login")
admin_login_button.place(x = 430, y= 230, width=100)
adminlogin_window.mainloop()
adminlogin_button = ttk.Button(root, text="Admin Login", command = adminlogin_function)
adminlogin_button.place(x=250, y=160, width = 200)
如何在 Toplevel() window 上使用 ttkthemes?它对根 window 工作正常,但它对顶级 window 不起作用。我找不到这方面的任何文档
您无需手动执行任何操作,一旦将主题应用到主要 window,所有其他 windows 和小部件都会继承主题,如果您在主题前加上前缀(从中导入)ttk
,比如:
ttk.Label(...)
ttk.Entry(....)
ttk.Button(...)
而且,adminlogin_window = tk.Toplevel()
不应该有 tk
,因为你的 tk
实际上是 from ttkthemes import themed_tk as tk
,所以只说:
adminlogin_window = Toplevel() #this uses toplevel from tkinter
您的函数将是:
def adminlogin_function():
# adminlogin_window configuration
adminlogin_window = Toplevel()
adminlogin_window.geometry("700x400")
# Widgets on adminlogin_window
admin_username_label = ttk.Label(adminlogin_window, text="Username")
admin_username_label.place(x=388, y=135)
admin_username_entry = ttk.Entry(adminlogin_window)
admin_username_entry.place(x =490 , y =135, width = 85)
admin_pass_label = ttk.Label(adminlogin_window, text="Password")
admin_pass_label.place(x = 388, y= 180)
admin_pass_entry = ttk.Entry(adminlogin_window,show="*")
admin_pass_entry.place(x =490 , y =180, width = 85)
admin_login_button = ttk.Button(adminlogin_window, text="Login")
admin_login_button.place(x = 430, y= 230, width=100)
注意这里我从小部件中删除了 fg
和 border
选项,因为 ttk
不支持他们的小部件的这些选项,更改它们相当麻烦。我还删除了 adminlogin_window.mainloop()
,因为 Toplevel
不需要 mainloop()
希望这消除了您的疑虑,如果有任何错误,请告诉我。
干杯
from tkinter import *
import tkinter.ttk as ttk
from tkinter import ttk
from ttkthemes import themed_tk as tk
import sqlite3
from PIL import Image, ImageTk
#Root window configuration
root = tk.ThemedTk()
root.get_themes()
root.set_theme('plastik')
root.geometry("500x500")
root.resizable(height=False, width=False)
def adminlogin_function():
# adminlogin_window configuration
# adminlogin_window = Toplevel()
adminlogin_window = tk.Toplevel()
adminlogin_window.get_themes()
adminlogin_window.set_theme('plastik')
adminlogin_window.geometry("700x400")
# Widgets on adminlogin_window
admin_username_label = Label(adminlogin_window, text="Username", fg="black")
admin_username_label.place(x=388, y=135)
admin_username_entry = Entry(adminlogin_window, border=2)
admin_username_entry.place(x =490 , y =135, width = 85)
admin_pass_label = Label(adminlogin_window, text="Password", fg="black")
admin_pass_label.place(x = 388, y= 180)
admin_pass_entry = Entry(adminlogin_window, border=2,show="*")
admin_pass_entry.place(x =490 , y =180, width = 85)
admin_login_button = Button(adminlogin_window, text="Login")
admin_login_button.place(x = 430, y= 230, width=100)
adminlogin_window.mainloop()
adminlogin_button = ttk.Button(root, text="Admin Login", command = adminlogin_function)
adminlogin_button.place(x=250, y=160, width = 200)
如何在 Toplevel() window 上使用 ttkthemes?它对根 window 工作正常,但它对顶级 window 不起作用。我找不到这方面的任何文档
您无需手动执行任何操作,一旦将主题应用到主要 window,所有其他 windows 和小部件都会继承主题,如果您在主题前加上前缀(从中导入)ttk
,比如:
ttk.Label(...)
ttk.Entry(....)
ttk.Button(...)
而且,adminlogin_window = tk.Toplevel()
不应该有 tk
,因为你的 tk
实际上是 from ttkthemes import themed_tk as tk
,所以只说:
adminlogin_window = Toplevel() #this uses toplevel from tkinter
您的函数将是:
def adminlogin_function():
# adminlogin_window configuration
adminlogin_window = Toplevel()
adminlogin_window.geometry("700x400")
# Widgets on adminlogin_window
admin_username_label = ttk.Label(adminlogin_window, text="Username")
admin_username_label.place(x=388, y=135)
admin_username_entry = ttk.Entry(adminlogin_window)
admin_username_entry.place(x =490 , y =135, width = 85)
admin_pass_label = ttk.Label(adminlogin_window, text="Password")
admin_pass_label.place(x = 388, y= 180)
admin_pass_entry = ttk.Entry(adminlogin_window,show="*")
admin_pass_entry.place(x =490 , y =180, width = 85)
admin_login_button = ttk.Button(adminlogin_window, text="Login")
admin_login_button.place(x = 430, y= 230, width=100)
注意这里我从小部件中删除了 fg
和 border
选项,因为 ttk
不支持他们的小部件的这些选项,更改它们相当麻烦。我还删除了 adminlogin_window.mainloop()
,因为 Toplevel
不需要 mainloop()
希望这消除了您的疑虑,如果有任何错误,请告诉我。
干杯