Geometry of Tkinter window

Basics of Python Tkinter

Tkinter window geometry to manage height width and zoom out using state and resizable() option


Our parent window is referred as my_w in all our examples below.
my_w = tk.Tk()

Resize the window

resizable window with disabled values There is a button at the top bar for the user to resize the parent window. By holding and dragging the edges we can resize the window.

We can prevent this by using resizable() option. By default width and height values are 1 ( True ).


my_w.resizable(width=0,height=0) # size change Not allowed 
We can only allow horizontally resizing the window.
my_w.resizable(width=1,height=0)

state

By managing the state method we can maximize the window to full screen. Values for this option are normal ( default value ) , iconic, withdrawn, or zoomed
my_w.state('zoomed')

Zooming the parent window

We can increse or decrease the width , height from inside the window by managing the geometry() option. We can place buttons in our window to zoom in or zoom out the parent window.
We used the click event of button to call a function my_resize() and inside it change the width and height of parent window.
Here is the full code.
import tkinter as tk
my_w = tk.Tk() # parent window 
width,height=300,200
v_dim=str(width)+'x'+str(height)
my_w.geometry(v_dim)  # Size of the window 
my_w.title("www.plus2net.com")  # Adding a title

def my_resize(condition):
    global width , height 
    if(condition=='increase'):
        width=width+10
        height=height+10
    elif(condition=='decrease'):
        width=width-10
        height=height-10
    
    d=str(width)+"x"+str(height) 
    my_w.geometry(d) # update the new width and height
    
b1=tk.Button(my_w,text='zoom ++ ',command=lambda:my_resize('increase'))
b1.grid(row=0,column=0,padx=10,pady=10)    
b2=tk.Button(my_w,text='zoom -- ',command=lambda:my_resize('decrease'))
b2.grid(row=0,column=1,padx=10,pady=10)  
b3=tk.Button(my_w,text='Full Screen',command=lambda:my_w.state('zoomed'))
b3.grid(row=0,column=2,padx=10,pady=10)   

my_w.mainloop()  # Keep the window open
Zoom in & out Text

Grid Layout place layout Frame rowconfigure() & columnconfigure()
Subscribe to our YouTube Channel here

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2022 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer