I have a app which uses ttkbootstrap and as a learning exercise wanted to turn it into a class based app. I am falling at the first hurdle so to speak as the basic window shows up as a different size.The first example is fine.
import tkinter as tk
from tkinter import *
import ttkbootstrap as tb
#root = tk.Tk()
root=tb.Window(themename="terry")
root.title("Stableford League")
root.geometry("1000x1000")
root.mainloop()
However the following produces a larger window:
import tkinter as tk
class App(tk.Tk):
def __init__(self):
super().__init__()
self.geometry("1000x1000")
if __name__ == "__main__":
app = App()
app.mainloop()
My screen resolution is 1920 x 1080 and scale is set to 150% but I cannot understand why the displayed windows are different sizes.
following your advice I arrive at the following code
import tkinter as tk
from tkinter import ttk
import ttkbootstrap as tb
from ttkbootstrap import Style
class App(tb.Window):
def __init__(self):
super().__init__()
self.title("Stableford League")
self.geometry("1000x1000")
self.style = Style(theme="terry")
if __name__ == "__main__":
app = App()
app.mainloop()
The line self.style = Style(theme = "terry") worked before inheriting from tb.Window but now throws an error.
The difference in window size is because ttkbootstrap
is DPI awareness, but tkinter
is not.
To apply certain theme when using class, you can either setting themename
option when initializing the class object:
class App(tb.Window):
def __init__(self):
super().__init__(themename='terry')
...
or set it using theme_use()
of Style
class:
class App(tb.Window):
def __init__(self):
super().__init__()
self.style.theme_use('terry')
...