Python Forum
[Tkinter] ttk and themes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] ttk and themes
#5
There are better looking libraries for Tkinter like ttkbootstrap or CustomTkinter
Quick test of ttkbootstrap,i got and error that i needed to fix locale.Error: unsupported locale setting
In dialogs.py:
#locale.setlocale(locale.LC_ALL, locale.setlocale(locale.LC_TIME, ""))
locale.setlocale(locale.LC_ALL, 'en_US.utf8')
import ttkbootstrap as ttk
from ttkbootstrap.constants import *

class DataEntryForm(ttk.Frame):
    def __init__(self, master):
        super().__init__(master, padding=(20, 10))
        self.pack(fill=BOTH, expand=YES)

        # form variables
        self.name = ttk.StringVar(value="")
        self.address = ttk.StringVar(value="")
        self.phone = ttk.StringVar(value="")

        # form header
        hdr_txt = "Please enter your contact information"
        hdr = ttk.Label(master=self, text=hdr_txt, width=50)
        hdr.pack(fill=X, pady=10)

        # form entries
        self.create_form_entry("name", self.name)
        self.create_form_entry("address", self.address)
        self.create_form_entry("phone", self.phone)
        self.create_buttonbox()

    def create_form_entry(self, label, variable):
        """Create a single form entry"""
        container = ttk.Frame(self)
        container.pack(fill=X, expand=YES, pady=5)

        lbl = ttk.Label(master=container, text=label.title(), width=10)
        lbl.pack(side=LEFT, padx=5)

        ent = ttk.Entry(master=container, textvariable=variable)
        ent.pack(side=LEFT, padx=5, fill=X, expand=YES)

    def create_buttonbox(self):
        """Create the application buttonbox"""
        container = ttk.Frame(self)
        container.pack(fill=X, expand=YES, pady=(15, 10))

        sub_btn = ttk.Button(
            master=container,
            text="Submit",
            command=self.on_submit,
            bootstyle=SUCCESS,
            width=6,
        )
        sub_btn.pack(side=RIGHT, padx=5)
        sub_btn.focus_set()

        cnl_btn = ttk.Button(
            master=container,
            text="Cancel",
            command=self.on_cancel,
            bootstyle=DANGER,
            width=6,
        )
        cnl_btn.pack(side=RIGHT, padx=5)

    def on_submit(self):
        """Print the contents to console and return the values."""
        print("Name:", self.name.get())
        print("Address:", self.address.get())
        print("Phone:", self.phone.get())
        return self.name.get(), self.address.get(), self.phone.get()

    def on_cancel(self):
        """Cancel and close the application."""
        self.quit()

if __name__ == "__main__":
    app = ttk.Window("Data Entry", "superhero", resizable=(False, False))
    DataEntryForm(app)
    app.mainloop()
[Image: mqnCfg.png]
Gribouillis and Larz60+ like this post
Reply


Messages In This Thread
ttk and themes - by DPaul - Nov-01-2023, 07:19 AM
RE: ttk and themes - by DPaul - Nov-01-2023, 10:52 AM
RE: ttk and themes - by Gribouillis - Nov-01-2023, 11:00 AM
RE: ttk and themes - by DPaul - Nov-01-2023, 12:45 PM
RE: ttk and themes - by snippsat - Nov-01-2023, 03:53 PM
RE: ttk and themes - by DPaul - Nov-01-2023, 06:21 PM
RE: ttk and themes - by snippsat - Nov-01-2023, 07:51 PM
RE: ttk and themes - by DPaul - Nov-02-2023, 07:05 AM
RE: ttk and themes - by DPaul - Nov-02-2023, 06:18 PM
RE: ttk and themes - by rob101 - Dec-02-2023, 01:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] installing 3rd party ttk themes twrackers 5 6,939 Mar-07-2019, 09:21 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020