2

I am trying to make a window that resizes using Tkinter, and it works fine. But I want the font size to scale to proportion as well. The entry boxes resize perfectly but the text just stays the same size. Can I change the entry text size as well? How do I do This?

Thank you in Advance.

Here is a snippet of my code so far:

# defining home page
master = Tk()

master.iconbitmap('program_icon.ico')
master.geometry("410x280")
master.configure(background="#ff4f30")
master.title("Emailer : Log In | Sign Up")

for i in range(1, 10, 1):
    master.rowconfigure(i, weight=3)
for i in range(1, 5, 1):
    master.columnconfigure(i, weight=3)

master.columnconfigure(1, weight=50)
master.rowconfigure(2, weight=50)
master.rowconfigure(3, weight=50)
master.rowconfigure(6, weight=50)
master.rowconfigure(7, weight=50)

# adding text
l1 = Label(master, text="Welcome to the Emailer \n Sign up or Log in \n Note: Your password is protected by hash encryption", bg="#ff4f30").grid(row=0, column=1, sticky=N+S+W+E)
l2 = Label(master, text="Log In", bg="#ff4f30").grid(row=1, column=1, sticky=N+S+W+E)
l3 = Label(master, text="Email", bg="#ff4f30").grid(row=2, sticky=N+S+W+E)
l4 = Label(master, text="Password", bg="#ff4f30").grid(row=3, sticky=N+S+W+E)

l5 = Label(master, text="Sign Up", bg="#ff4f30").grid(row=5, column=1, sticky=N+S+W+E)
l6 = Label(master, text="Email", bg="#ff4f30").grid(row=6, sticky=N+S+W+E)
l7 = Label(master, text="Password", bg="#ff4f30").grid(row=7, sticky=N+S+W+E)

# adding top menu
menubar = Menu(master)
menubar.add_command(label="Help", command=helpuser)
menubar.add_command(label="Quit", command=master.quit)
master.config(menu=menubar)

# defining user input boxes
e1 = Entry(master)
e2 = Entry(master)
e3 = Entry(master)
e4 = Entry(master)

e1.grid(row=2, column=1, sticky=N+S+W+E)
e2.grid(row=3, column=1, sticky=N+S+W+E)
e3.grid(row=6, column=1, sticky=N+S+W+E)
e4.grid(row=7, column=1, sticky=N+S+W+E)

# setting e2 and e4 to only display '*' character
e2.config(show="*")
e4.config(show="*")

# defining buttons
Button(master, text='Sign Up', command=sign_up).grid(row=8, column=2, sticky=W + E, pady=4)
Button(master, text='Log In', command=log_in).grid(row=4, column=2, sticky=W + E, pady=4)

# starting window
mainloop( )
1

1 Answer 1

3

maybe you can use a font object and develop a function bound to the window being resized ?

import tkinter as tk
import tkinter.font as tkFont


master = tk.Tk()
my_font = tkFont.Font(size=10)
def resizer(event):
   if event.width in range(300,325):
      my_font.configure(size=10)   
   elif event.width in range(400,425):
      my_font.configure(size=20)
   elif event.width > 600:
      my_font.configure(size=30)

a_label= tk.Label(font=my_font, text="Welcome")
a_label.grid()
an_entry = tk.Entry(font=my_font)
an_entry.grid()
an_entry.insert(0,'some text')
master.bind("<Configure>", resizer)
tk.mainloop()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.