'How to scale window, fonts, labels in tkinter
I am truly struggling to find out how I can window scale my program. The program is a very simple thing that shows local time and UTC time using tkinter.
Now I can scale the window using Sizegrip with the pack method, however I am having trouble getting the fonts scaled with the window.
I have tried to search the web and watched videos by Codemy but have not found any page or video that target or solve my issue. Please note that due to my knowledge level of Python, I do not want to over complicate my program to the point I do not understand how.
Here is my program:
import datetime as dt
import pytz
import tkinter as Tk
from tkinter import ttk
#TK TimeZone v1.00 by Tom Knudsen
# A small program to show local time and utc time!
#Creating a window
root = Tk.Tk()
root.title("TK Zulu Clock")
root.geometry("580x640")
#Make the window sizeable
root.resizable(True,True)
my_sizegrip = ttk.Sizegrip(root)
my_sizegrip.pack(side="right", anchor="se")
mylabel1 = Tk.Label(root, text="Local Time", font=("Arial", 25))
mylabel1.pack()
mylabel2 = Tk.Label(root, font=("Arial", 100))
mylabel2.pack()
mylabel3 = Tk.Label(root, text="Zulu Time", font=("Arial", 25))
mylabel3.pack(pady=20)
mylabel4 = Tk.Label(root, font=("Arial", 100))
mylabel4.pack()
#Changing font sizes
def changefont():
mylabel1.config(size=25)
mylabel3.config(size=25)
#Defining a function to display local time
def timezone1():
dt1 = dt.datetime.now().strftime("%H:%M:%S")
mylabel2.config(text= dt1)
mylabel2.after(1000, timezone1)
#Defining a function to display UTC time
def timezone2():
dt2 = dt.datetime.now(pytz.utc).strftime("%H:%M:%S")
mylabel4.config(text=dt2)
mylabel4.after(1000, timezone2)
timezone1()
timezone2()
root.mainloop()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
