问题描述
所以我正在尝试构建一个小型应用程序,我真的很喜欢 Guizero 程序包,它是简单的事件驱动编程。
它似乎唯一缺少的是实现主题更改的方法,因此目前看起来确实过时了。有没有办法应用Tkinter包之类的?
以下是我尝试过的一些代码,它甚至可以正确打印出“vista”,但似乎没有实现实际的主题更改。
from tkinter import *
from guizero import *
import tkinter.ttk as ttk
app = App(title="Application Name",layout="grid",height=200,width=600) # Random app name
app.tk.iconbitmap("someicon.ico") # I got this to work
s=ttk.Style()
#app.ttk.Style().theme_use('default')
print(s.theme_names()) # loads themes
print(s.theme_use()) # shows potential theme names ('winnative','clam','alt','default','classic','vista','xpnative')
s.theme_use('vista')
print(s.theme_use()) # prints 'vista'
app.style = s
print(app.style.theme_use()) # prints 'vista'
app.display()
解决方法
这不是 ttk,但您仍然可以设计您想要的样式。
from guizero import *
app = App()
#app.icon="images/Icon.ico"
#Changes in version 1.2.0
#https://lawsie.github.io/guizero/changelog/
#.icon does not work on Window()
#you will need to use WindowsName.tk.iconbitmap("Icon.ico")
#when creating a second window or more
def do_nothing():
print("Button was pressed")
#tkinter widget Properties
#https://www.tutorialspoint.com/python/python_gui_programming.htm
def elementsName(Name):
#example of Guizero property
#Name.bg='green'
#these are button widget properties
Name.tk.config(width=5,height=1,borderwidth=0,relief="groove",activeforeground='darkgray',activebackground='green',highlightthickness=0,#highlightcolor="blue",bg='blue',fg='orange'
)
button1 = PushButton(app,text='button',command=do_nothing)
button1.text_size=15
button2 = PushButton(app,text='button2',command=do_nothing)
button2.text_size=15
#do no use '' or "" inside this tuple.
buttonsNames=(button1,button2)
#works for group of elements doesn't
#work on single elements/widgets
for x in buttonsNames:
elementsName(x)
#How to style just one elements/widget
'''
using tkinter config
WidgetsName.tk.config(property1,property2,property3,)
Using Guizero to list each property separately
WidgetsName.text_size=12
WidgetsName.text_color= 'gray'
'''
app.display()