Tkinter azure theme example 3

REPL

Custom REPL

packages = [ "bokeh", "numpy" ] plugins = [ "https://pyscript.net/latest/plugins/python/py_tutor.py" ] [[fetch]] files = ["./utils.py", "./antigravity.py"]

Another example using classes to create optionmenu and label widgets like the ones you see in the following images. We are using ttk for more modern and stylish widgets, with a dark theme.

The code for the widgets

# Importing Tkinter and Ttk
import tkinter as tk
from tkinter import ttk

class Window:
	def __init__(self):
		# Create the window
		self.create_window()

	def create_window(self):
		self.root = tk.Tk()
		self.root.title('Azure - Option Menu')

		# Place the window in the center of the screen
		self.windowWidth = 800
		self.windowHeight = 530
		self.screenWidth = self.root.winfo_screenwidth()
		self.screenHeight = self.root.winfo_screenheight()
		self.xCordinate = int((self.screenWidth/2) - (self.windowWidth/2))
		self.yCordinate = int((self.screenHeight/2) - (self.windowHeight/2))
		self.root.geometry("{}x{}+{}+{}".format(self.windowWidth, self.windowHeight, self.xCordinate, self.yCordinate))
		# Create a style
		self.style = ttk.Style(self.root)
		self.style.configure("Button", background="red")
		self.style.map('Button', background=[('active','red')])
		# Import the tcl file
		self.root.tk.call('source', 'azure dark/azure dark.tcl')
		# Set the theme with the theme_use method
		self.style.theme_use('azure')


class Option(Window):
	def __init__(self):
		print("Optionmenu istanciated")

	def create_option_list(self,win,x,y,lst):
		self.option_list = lst
		self.e = tk.StringVar(value=self.option_list[1])
		self.optionmenu = ttk.OptionMenu(win.root, self.e, *self.option_list)
		self.optionmenu.place(x=x, y=y)


class Label(Window):
	def __init__(self):
		print("Label istance")

	def create_label(self,win,x,y,text):
		# Creating lists
		# self.e = tk.StringVar(value=text)
		self.label = ttk.Label(win.root, text=text)
		self.label.place(x=x, y=y)

w = Window()

option1 = Option().create_option_list(w,10,10,
			['', 'OptionMenu 1', 'Value 1', 'Value 3'])
option2 = Option().create_option_list(w,150,10,
			['', 'OptionMenu 2', 'Value 1', 'Value 3'])
label1 = Label().create_label(
			w,100,100,text="Ciao a tutti")
label2 = Label().create_label(
			w,100,200,text="See you later")
w.root.mainloop()

Alternative code

You can use this code down here, if you prefer

# Importing Tkinter and Ttk
import tkinter as tk
from tkinter import ttk

class Window:
	def __init__(self):
		# Create the window
		self.root = tk.Tk()
		self.root.title('Azure - Option Menu')

		# Place the window in the center of the screen
		self.windowWidth = 800
		self.windowHeight = 530
		self.screenWidth = self.root.winfo_screenwidth()
		self.screenHeight = self.root.winfo_screenheight()
		self.xCordinate = int((self.screenWidth/2) - (self.windowWidth/2))
		self.yCordinate = int((self.screenHeight/2) - (self.windowHeight/2))
		self.root.geometry("{}x{}+{}+{}".format(self.windowWidth, self.windowHeight, self.xCordinate, self.yCordinate))
		# Create a style
		self.style = ttk.Style(self.root)
		self.style.configure("Button", background="red")
		self.style.map('Button', background=[('active','red')])
		# Import the tcl file
		self.root.tk.call('source', 'azure dark/azure dark.tcl')
		# Set the theme with the theme_use method
		self.style.theme_use('azure')


	def create_option_list(self,x,y,lst):
		# Creating lists
		self.option_list = lst
		self.e = tk.StringVar(value=self.option_list[1])
		self.optionmenu = ttk.OptionMenu(self.root, self.e, *self.option_list)
		self.optionmenu.place(x=x, y=y)

	def create_label(self,x,y,text):
		self.label = ttk.Label(self.root, text=text)
		self.label.place(x=x, y=y)


w = Window()
o1 = w.create_option_list(10,10,
	['', 'OptionMenu 1', 'Value 1', 'Value 3'])
o2 = w.create_option_list(150,10,
	['', 'OptionMenu 2', 'Value 1', 'Value 3'])
l1 = w.create_label(10,50,"First label")
l2 = w.create_label(10,100,"Second label")

w.root.mainloop()

the repository of examples of tkinter windows with azure dark them

https://github.com/formazione/Azure-ttk-theme.git


Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

https://x.com/pythonprogrammi/status/1706027213093478740?s=20

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.