对象已移动

可在此处找到该文档 Python: How to Use Tkinter’s Grid Manager – New Self New Life
New Self New Life
No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
New Self New Life
No Result
View All Result
Home Softwares

Python: How to Use Tkinter’s Grid Manager

by admin
3 years ago
in Softwares
Python: How to Use Tkinter’s Grid Manager
Share on FacebookShare on Twitter


Python’s Tkinter library has quite a few instruments for managing the size of widgets in GUI-based purposes. These instruments are known as geometry managers. The grid supervisor is certainly one of these instruments. It has extra flexibility and customization than the generally used .pack() supervisor. We’ll learn to use the .grid() geometry supervisor in right now’s Python programming tutorial.

Learn: How To Create Your First Python GUI Software

Create a Grid in Tkinter and Python

To create a grid, it is advisable to use the .grid() technique. This technique can be utilized on each home windows and frames.

The grid() technique lets you point out the row and column positioning in its parameter checklist. Each row and column begin from index 0. For instance grid(row=1, column=2) specifies a place on the third column and second row of your body or window.

Python Tkinter Grid Manager

The Python code instance under exhibits how one can get the grid picture above:

import tkinter as tk
 
window = tk.Tk()
window.title("Grid Supervisor")
 
for x in vary(2):
   for y in vary(2):
       body = tk.Body(
           grasp=window,
           aid=tk.RAISED,
           borderwidth=1
       )
       body.grid(row=x, column=y)  # line 13
       label = tk.Label(grasp=body, textual content=f"nnrow {x}tt column {y}nn")
       label.pack()
 
window.mainloop()
 

Learn: Create Textual content Widgets in Python with Tkinter

Add Padding to a Tkinter Grid

You could have observed that the frames within the earlier instance are a little bit too shut collectively. You may add some house between these frames through a technique generally known as padding.

There are two forms of padding: exterior and inner. Exterior padding lets you place house in between the skin of the widgets. You may implement it by utilizing the 2 variables padx and pady. Padx inserts house horizontally, whereas pady inserts house vertically. These two values are measured in pixels.

For instance, within the earlier code instance, you possibly can create equal spacing in both route with the code under:

body.grid(row=x, column=y padx=10 pady=10)  # line 13

Dynamically Resizing Tkinter Grids

In case you attempt to modify the window created within the earlier instance, you’ll discover that the grid stays on the prime left hand nook and isn’t aware of the window resizing. You may be certain that your grid is dynamically resized with the window by utilizing the columnconfigure() and rowconfigure() strategies. These strategies apply to the window object.

The columnconfigure() technique resizes the grid vertically, whereas rowconfigure() resizes the grid horizontally. Each of those strategies soak up 3 arguments:

  • Index of row/column
  • minsize: This defines the minimal measurement of the widget. That is mandatory for readability functions, in order that the smallest doable resizing continues to be moderately readable.
  • weight. This can be a measure of the resizing ratio of a column or row relative to different columns or rows. For instance, a weight of 1 signifies that a column or row resizes on the similar fee as different columns or rows. A weight of three signifies that a row or column resizes at thrice the speed of different rows or columns. By default, this discipline is ready to 0, implying {that a} row or column doesn’t resize because the window resizes.

See the code instance under:

import tkinter as tk
 
window = tk.Tk()
window.title("Grid Supervisor")
 
for x in vary(2):
   window.columnconfigure(x, weight=1, minsize=100)
   window.rowconfigure(x, weight=1, minsize=75)
   for y in vary(2):
       body = tk.Body(
           grasp=window,
           aid=tk.RAISED,
           borderwidth=1
       )
       body.grid(row=x, column=y, padx=10, pady=10)  # line 13
       label = tk.Label(grasp=body, textual content=f"row {x}ncolumn {y}")
       label.pack()
 
window.mainloop()

Learn: High On-line Programs To Study Python

Summing Up Tkinter’s Grid Supervisor

Tkinter’s grid supervisor lets you place your widgets. Do not forget that in case you want to house your widgets, through which case it is advisable to apply padding.

To attain dynamic resizing of Tkinter grids, Python builders want to make use of the columnconfigure() and rowconfigure() strategies. You will need to do not forget that these strategies apply to the window object and never grid().

Learn extra Python programming tutorials and developer guides.



Source link

Tags: GridManagerPythonTkinters
Previous Post

Handoff Tools For Designers and Developers Collaboration

Next Post

Sauti Sol reigned supreme, thrilled fans at Magical Kenya Open Village #TBT

Related Posts

Further Tab Button work and Chromium 140 – Vivaldi Browser snapshot 3787.3
Softwares

Further Tab Button work and Chromium 140 – Vivaldi Browser snapshot 3787.3

by admin
August 23, 2025
Find a Software Development Company in Europe
Softwares

Find a Software Development Company in Europe

by admin
August 24, 2025
Xero Salesforce Integration – The Definitive Guide
Softwares

Xero Salesforce Integration – The Definitive Guide

by admin
August 20, 2025
BrowserStack launches Chrome extension that bundles 10+ manual web testing tools
Softwares

BrowserStack launches Chrome extension that bundles 10+ manual web testing tools

by admin
August 18, 2025
20+ Best Titles Templates for DaVinci Resolve in 2025 — Speckyboy
Softwares

20+ Best Titles Templates for DaVinci Resolve in 2025 — Speckyboy

by admin
August 22, 2025
Next Post
Sauti Sol reigned supreme, thrilled fans at Magical Kenya Open Village #TBT

Sauti Sol reigned supreme, thrilled fans at Magical Kenya Open Village #TBT

New movie trailers: Where the Crawdads Sing, Men, Charlotte, Umma and more.

  • Trending
  • Comments
  • Latest
10 Best Netflix Original Thriller Shows, Ranked

10 Best Netflix Original Thriller Shows, Ranked

June 22, 2025
I Only Have More Questions After Another Bizarre Outing With The Harrigans

I Only Have More Questions After Another Bizarre Outing With The Harrigans

April 20, 2025
‘Rust’ armorer’s involuntary manslaughter conviction upheld in fatal shooting – National

‘Rust’ armorer’s involuntary manslaughter conviction upheld in fatal shooting – National

October 1, 2024
Harvey Weinstein case judge declares mistrial on remaining rape charge – National

Harvey Weinstein case judge declares mistrial on remaining rape charge – National

June 13, 2025
Lil Nas X hospitalized in Los Angeles for ‘possible overdose,’ say reports – National

Lil Nas X hospitalized in Los Angeles for ‘possible overdose,’ say reports – National

August 22, 2025
Best AI Webcams For Video Calls In 2025

Best AI Webcams For Video Calls In 2025

August 21, 2025
Paul Walter Hauser on ‘Americana’ and Not Fitting in Hollywood

Paul Walter Hauser on ‘Americana’ and Not Fitting in Hollywood

August 20, 2025
Meta Gains New Ad Safety Certifications for Facebook and Instagram

Meta Rolls Out Changes to Its Ad Billing Settings

August 22, 2025
Dafne Keen and Saara Chaudry Join the Season 3 Cast of PERCY JACKSON AND THE OLYMPIANS — GeekTyrant

Dafne Keen and Saara Chaudry Join the Season 3 Cast of PERCY JACKSON AND THE OLYMPIANS — GeekTyrant

August 25, 2025
Robert Irwin spots his late father Steve Irwin’s star on Hollywood Walk of Fame, new video

Robert Irwin spots his late father Steve Irwin’s star on Hollywood Walk of Fame, new video

August 25, 2025
Snapped: Dirtybird Campout x Northern Nights (A Photo Essay)

Snapped: Dirtybird Campout x Northern Nights (A Photo Essay)

August 24, 2025
13 Famous Parents Whose Children Have Big Age Gaps

13 Famous Parents Whose Children Have Big Age Gaps

August 24, 2025
Where Is Shelley Long Now? Inside Her Quiet Life After Cheers

Where Is Shelley Long Now? Inside Her Quiet Life After Cheers

August 24, 2025
Meta To Launch Affordable AR Glasses In September

Meta To Launch Affordable AR Glasses In September

August 24, 2025
Visions’ Season 3 Puts a Stormtrooper on Death’s Door

Visions’ Season 3 Puts a Stormtrooper on Death’s Door

August 23, 2025
‘Wind Talk To Me’ Wins Best Feature At Sarajevo Film Festival

‘Wind Talk To Me’ Wins Best Feature At Sarajevo Film Festival

August 23, 2025
New Self New Life

Your source for entertainment news, celebrities, celebrity news, and Music, Cinema, Digital Lifestyle and Social Media and More !

Categories

  • Celebrity
  • Cinema
  • Devices
  • Digital Lifestyle
  • Entertainment
  • Music
  • Social Media
  • Softwares
  • Uncategorized

Recent Posts

  • Dafne Keen and Saara Chaudry Join the Season 3 Cast of PERCY JACKSON AND THE OLYMPIANS — GeekTyrant
  • Robert Irwin spots his late father Steve Irwin’s star on Hollywood Walk of Fame, new video
  • Snapped: Dirtybird Campout x Northern Nights (A Photo Essay)
  • Home
  • Disclaimer
  • DMCA
  • Privacy Policy
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites. slotsfree  creator solana token

No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites.

New Self New Life