Python Forum
[Tkinter] Trouble changing Font within tkinter frame title
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Trouble changing Font within tkinter frame title
#2
I did a version of your code. You can look at the way I did the styling and maybe it will help.
#! /usr/bin/env python3

import tkinter as tk
from tkinter import ttk
from ttkbootstrap import Style
import sys

class Window:
    def __init__(self, parent):
        self.parent = parent
        self.parent.rowconfigure(0, weight=1)
        self.parent.columnconfigure(0, weight=1)

        # Create some styles
        exit_btn = Style()
        exit_btn.map('danger.TButton', background = [
        ('disabled', 'tomato'), ('active', 'red')])
        exit_btn.configure('danger.TButton', font=('verdana', 12, 'bold'))

        nb = ttk.Style()
        cur_nb_theme = nb.theme_use()
        nb.theme_settings(cur_nb_theme, {'TNotebook.Tab': {'configure':
                                        {'font': ('comic sans ms', 12, 'bold'),
                                         'foreground': 'blue', 'background': 'lightblue'}
                                        }})


        # Container frame to hold everything
        container = tk.Frame(self.parent)
        container.grid(column=0, row=0, sticky='news')
        container.grid_columnconfigure(0, weight=3)

        # Configure the header
        label = tk.Label(container)
        label['text'] = 'DGRF Frequency Synthesizer 45 MHz - 22 GHz'
        label['font'] = ('comic sans ms', 18, 'bold')
        label['foreground'] = 'steel blue'
        label['relief'] = 'groove'
        label['pady'] = 3
        label.grid(column=0, row=0, sticky='new')

        # Create the notebook
        notebook = ttk.Notebook(container)
        notebook.grid(column=0, row=1, sticky='new')

        # Create and add the tabs
        tab1 = ttk.Frame(notebook)
        tab1.grid(column=0, row=0, sticky='new')

        tab2 = ttk.Frame(notebook)
        tab2.grid(column=1, row=0, sticky='new')

        notebook.add(tab1, text='Reference Chain')
        notebook.add(tab2, text='CW Output')

        # Create a container frame for the two info frames and button
        btm_container = tk.Frame(container)
        btm_container.grid(column=0, row=2, sticky='new', pady=3)
        btm_container.grid_columnconfigure(0, weight=1)
        btm_container.grid_columnconfigure(1, weight=3)
        btm_container.grid_columnconfigure(2, weight=1)
        # for i in range(3):
        #     btm_container.grid_columnconfigure(i, weight=3, uniform='btm')

        # Create error message label
        error_label = ttk.Label(btm_container, anchor='w', background='lightblue')
        error_label['text'] = 'Error Messages:'
        error_label['padding'] = [10, 0, 0, 0]
        error_label['font'] = ('tahoma', 10, 'bold')
        error_label['foreground'] = 'navy'
        error_label.grid(column=0, row=0, sticky='news')

        # Create message label
        message = ttk.Label(btm_container, anchor='w', background='lightblue')
        message['text'] = 'Please Initialize'
        message['font'] = ('tahoma', 10, 'italic bold')
        message.grid(column=1, row=0, sticky='news')

        btn = ttk.Button(btm_container, text='Exit', cursor='hand2')
        btn['command'] = self.exit
        btn['style'] = 'danger.TButton'
        btn.grid(column=2, row=0, sticky='new', padx=2)

        # Create some data for the tabs
        for i in range(20):
            label = tk.Label(tab1, text=f'Line {i} text for tab1')
            label.grid(column=0, row=i, sticky='news')

        for i in range(20):
            label = tk.Label(tab2, text=f'Line {i} text for tab2')
            label.grid(column=0, row=i, sticky='news')

    # Create the method/function for the exit button
    def exit(self):
        sys.exit()

def main():
    root = tk.Tk()
    # root.geometry('800x600+250+250')
    # root.resizable(0, 0)
    root['padx'] = 5
    root['pady'] = 3
    root.title('Part Number: DGRF2820 Rev1      Software ver 1.0')
    Window(root)
    root.mainloop()

if __name__ == '__main__':
    main()
[attachment=1291]
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
RE: Trouble changing Font within tkinter frame title - by menator01 - Sep-30-2021, 05:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] TKinter Remove Button Frame Nu2Python 8 1,022 Jan-16-2024, 06:44 PM
Last Post: rob101
  Trouble with Tkinter labels Raysz 6 1,571 Sep-11-2023, 02:58 PM
Last Post: deanhystad
  [Tkinter] Help running a loop inside a tkinter frame Konstantin23 3 1,596 Aug-10-2023, 11:41 AM
Last Post: Konstantin23
  tkinter mapview in a frame janeik 2 1,337 Jun-22-2023, 02:53 PM
Last Post: deanhystad
  [Tkinter] Tkinter Window Has no Title Bar gw1500se 4 2,871 Nov-07-2021, 05:14 PM
Last Post: gw1500se
  tkinter frame camera opencv Nick_tkinter 9 5,474 Mar-21-2021, 06:41 PM
Last Post: Nick_tkinter
  Tkinter menu font size -method to change tonycat 2 7,874 Oct-11-2020, 02:43 AM
Last Post: tonycat
  [Tkinter] How to Print a list = ['a','b','c'], using tkinter along with a custom font? Pleiades 2 2,389 Sep-15-2020, 03:54 PM
Last Post: Pleiades
  [Tkinter] Trying to change font size w/o changing button size python63 3 9,888 Aug-05-2020, 01:04 AM
Last Post: Larz60+
  [Tkinter] Tkinter delete values in Entries, when I'm changing the Frame robertoCarlos 11 5,871 Jul-29-2020, 07:13 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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