How to add theme/style to GUIZERO python3 package

593 Views Asked by At

So I'm trying to build a small app, and I really enjoy the Guizero package and it's easy, event-driven programming.

The only thing it seems to lack is a method to implement theme changes, so it looks really outdated at the moment. Is there a way to apply Tkinter packages or something?

Below is some code I've tried, and it even prints 'vista' out correctly, but it doesn't seem to implement the actual theme change.

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()
1

There are 1 best solutions below

4
On BEST ANSWER

This is not ttk but you can still style what you want.

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()