Giter Club home page Giter Club logo

forest-ttk-theme's Introduction

Forest theme for ttk

Partially based on my Azure theme

image image

How to use

Python / tkinter

To use the theme just import the forest-light.tcl, or the forest-dark.tcl file, and call the theme_use method to set the theme:

# Import the tcl file
root.tk.call('source', 'forest-light.tcl / forest-dark.tcl')

# Set the theme with the theme_use method
ttk.Style().theme_use('forest-light / forest-dark')

Tcl / tk

To use the theme just import the forest-light.tcl, or the forest-dark.tcl file, and call the theme use method to set the theme:

# Import the tcl file
source "forest-light.tcl / forest-dark.tcl"

# Set theme using the theme use method
ttk::style theme use forest-light / forest-dark

New style elements

The Forest theme similar to my Azure theme has some new widget styles, such as an accent button, toggle switch, toggle button and card. You can apply these with the style option.

If you need a highlighted button, use Accent.TButton:

button = ttk.Button(root, text='Accent button', style='Accent.TButton', command=callback)

To create a toggle button you need a checkbutton, to which you can apply the ToggleButton style:

togglebutton = ttk.Checkbutton(root, text='Toggle button', style='ToggleButton', variable=var)

The use of switches is becoming more common these days, so this theme has a Switch style, that can be applied to checkbuttons:

switch = ttk.Checkbutton(root, text='Switch', style='Switch', variable=var)

If you only want a border around your widgets, not an entire LabelFrame then apply the Card style to a Frame:

card = ttk.Frame(root, style='Card', padding=(5, 6, 7, 8))

A short example

for Python...

import tkinter as tk
from tkinter import ttk

root = tk.Tk()

# Import the tcl file
root.tk.call('source', 'forest-dark.tcl')

# Set the theme with the theme_use method
ttk.Style().theme_use('forest-dark')

# A themed (ttk) button
button = ttk.Button(root, text="I'm a themed button")
button.pack(pady=20)

root.mainloop()

...and for Tcl

package require Tk 8.6

# Import the tcl file
source "forest-dark.tcl"

# Set theme using the theme use method
ttk::style theme use forest-dark

# A themed (ttk) button
ttk::button .button -text "I'm a themed button"
pack .button -pady 20

forest-ttk-theme's People

Contributors

rdbende avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

forest-ttk-theme's Issues

hitting toggle CheckButton repeatedly causes TreeView to keep expanding

This is my code.
If I keep hitting that toggle button the treeview just keeps expanding and finally goes out of screen.

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
style = ttk.Style(root) 
root.tk.call('source','./forest-light.tcl')
root.tk.call('source','./forest-dark.tcl')
style.theme_use('forest-dark')

def toggle_mode():
    if mode_switch.instate(['selected']):
        style.theme_use('forest-light')
    else:
        style.theme_use('forest-dark')

frame = ttk.Frame(root)
frame.pack()

widgets_frame = ttk.LabelFrame(frame, text='Label Frame')
widgets_frame.grid(row=0,column=0,padx=20,pady=10)

mode_switch = ttk.Checkbutton(widgets_frame,text='Mode',style='Switch', command=toggle_mode)
mode_switch.grid(row=0,column=0,padx=5,pady=10,sticky='nsew')



tree_frame = ttk.Frame(frame)
tree_frame.grid(row=0,column=1,pady=10)

# scrollbar needs to be added and attached to treeview
treescroll = ttk.Scrollbar(tree_frame)
treescroll.pack(side='right',fill='y') # fill entire vertical axis 

# treeview
excel_columns = ['name','age','subscription','employment']

treeview = ttk.Treeview(tree_frame,
                        show='headings',
                        columns=excel_columns, 
                        height=11, 
                        yscrollcommand=treescroll.set)

treeview.column('name',width=100)
treeview.column('age',width=40)
treeview.column('subscription',width=100)
treeview.column('employment',width=100)

treeview.pack()
treescroll.config(command=treeview.yview) 

root.mainloop()

I was following a tutorial based of here
https://github.com/codefirstio/tkinter-excel-app/blob/main/main.py
https://www.youtube.com/watch?v=8m4uDS_nyCk&ab_channel=CodeFirstwithHala

Changing between light and dark mode

Hi, first of all, I'd like to thank you for the nice theme. I like it a lot, I am currently trying to make a button to switch from one theme to the other. I have my default set at the dark forest theme. Using the code attached I am trying to change the themes. I am able to change from dark to light mode. However, when trying to change from light back to dark, I get the following error: in change_theme root.tk.call('source', tclfile) _tkinter.TclError: Theme forest-dark already exists. What am I missing?

tclfile='forest-dark.tcl'
themename='forest-dark'
root.tk.call('source', tclfile)
ttk.Style().theme_use(themename)

def change_theme():
    global themename, tclfile
    if themename == 'forest-dark':
        tclfile = 'forest-light.tcl'
        themename = 'forest-light'
        root.tk.call('source', tclfile)
        ttk.Style().theme_use(themename)
        print(themename)
    elif themename=='forest-light':
        themename = 'forest-dark'
        tclfile = 'forest-dark.tcl'

        root.tk.call('source', tclfile)
        ttk.Style().theme_use(themename)

Accent colour

Hi

Is it possible to change the accent theme colour for buttons. For example in dark mode the accent colours are green or grey. how do we change the colours if possible ?

Switch color

Hello rdbende.

The color of the Switch element in the Forest theme is always colored (green), no matter if set to On or to Off. This can be also seen in the screenshots included in the project repository. In comparison, the color of the Switch in the Azure theme is grey for Off and colored for On, which makes perfect sense. I do not know if is it a little tiny error in the Forest theme or if it works as intended. If the current behavior is intended, the issue could be closed.

Last but not least. I am still amazed with all the great work you have uploaded to GitHub and especially with all these beautiful themes. Thank you! I already gave a handful of stars to your repositories.

Style cause lagging

I made a GUI with buttons, image, treeview, entries, scrollbars, comboboxes, listboxes.
My program start lagging when I drag and move the root window. I had no idea what cause this issue then I turned off the light-forest theme and the lagg gone. Has anybody noticed something similar?

No matter what I try, cannot get this to work

Currently using azure theme azure.tcl, and swapped it for this. Cannot get it to work no matter what I try. I have it in the root directory of the python script, with folders theme > forest_light. I get this error:

_tkinter.TclError: no files matched glob pattern "*.png"

Python code:

  ```
  import tkinter as tk
  from tkinter import messagebox
  from tkinter import ttk
  
  # Get the path to the directory where the script is located
  script_dir = os.path.dirname(os.path.abspath(__file__))
  
  # Build the full path to the forest-light.tcl file
  tcl_path = os.path.join(script_dir, "forest-light.tcl")
  
  # Create the root window
  root = tk.Tk()
  root.title("windowtitle")
  
  
  
  
  # Pack a big frame so, it behaves like the window background
  big_frame = ttk.Frame(root)
  big_frame.pack(fill="both", expand=True)
  
  # Create a style
  style = ttk.Style(root)
  
  # Import the forest-light.tcl file using the full path
  root.tk.call("source", tcl_path)
  
  # Set the theme with the theme_use method
  style.theme_use("forest-light")
  
  
  # Create the main notebook
  main_notebook = ttk.Notebook(big_frame)
  main_notebook.pack(fill=tk.BOTH, expand=True)
  
  # Create the desktop view frame
  desktop_view = tk.Frame(main_notebook)
  main_notebook.add(desktop_view, text="Desktop")
  
  # Create the mobile view frame
  mobile_view = tk.Frame(main_notebook)
  main_notebook.add(mobile_view, text="Mobile")
  
  # Create the menu bar
  menubar = tk.Menu(root)
  root.config(menu=menubar)
  ```

Appears that even the example.py doesn't work from downloading the entire forest-ttk folder:

image

_File "c:\Users\josep\Downloads\Forest-ttk-theme-master\Forest-ttk-theme-master\example.py", line 29, in
root.tk.call("source", "forest-dark.tcl")
tkinter.TclError: couldn't read file "forest-dark.tcl": no such file or directory

Text box

It seems only entry boxes are supported, which makes text a bit of an eyesore - the only option if I need multiline input

Love the theme, thanks!

keyboard & switch

Hi, rdbende!

Perhaps, most annoying issue of the themes: in fact they are unusable with keyboard because there is no highlighting the focused widgets. And you never know which button is focused if there are several of them, so "don't press Enter/Space" is a rule.

Second issue is that the Switch widget seems to be unusable in forest theme, as "ttk::style layout Switch.TCheckbutton" isn't present in it at all.

I've tried to modify your theme to overcome these issues. The result is seen in the attached videos. The "before" video refers to the original theme, "after" to the modified one. Note that the keyboard is only used, the mouse being inactive.

For your consideration, the source (themes.zip) is attached too. The forest theme has undergone the most modifications, as seen in its video. I'd even changed main colors, but it's only my taste, never mind.

Take this stuff for a humble base to make your themes better.

Thanks a lot for your work, it's so well made!

With respect,
Alex

before.mp4
after.mp4
forest.mp4

themes.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.