Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python tkinter grid

# import tkinter module
from tkinter import * from tkinter.ttk import *
  
# creating main tkinter window/toplevel
master = Tk()
  
# this will create a label widget
l1 = Label(master, text = "Height")
l2 = Label(master, text = "Width")
  
# grid method to arrange labels in respective
# rows and columns as specified
l1.grid(row = 0, column = 0, sticky = W, pady = 2)
l2.grid(row = 1, column = 0, sticky = W, pady = 2)
  
# entry widgets, used to take entry from user
e1 = Entry(master)
e2 = Entry(master)
  
# this will arrange entry widgets
e1.grid(row = 0, column = 1, pady = 2)
e2.grid(row = 1, column = 1, pady = 2)
  
# checkbutton widget
c1 = Checkbutton(master, text = "Preserve")
c1.grid(row = 2, column = 0, sticky = W, columnspan = 2)
  
# adding image (remember image should be PNG and not JPG)
img = PhotoImage(file = r"C:UsersAdminPicturescapture1.png")
img1 = img.subsample(2, 2)
  
# setting image with the help of label
Label(master, image = img1).grid(row = 0, column = 2,
       columnspan = 2, rowspan = 2, padx = 5, pady = 5)
  
# button widget
b1 = Button(master, text = "Zoom in")
b2 = Button(master, text = "Zoom out")
  
# arranging button widgets
b1.grid(row = 2, column = 2, sticky = E)
b2.grid(row = 2, column = 3, sticky = E)
  
# infinite loop which can be terminated 
# by keyboard or mouse interrupt
mainloop()
Comment

Example Layout using grid() in tkinter

# import tkinter module
from tkinter import * from tkinter.ttk import *
 
# creating main tkinter window/toplevel
master = Tk()
 
# this will create a label widget
l1 = Label(master, text = "First:")
l2 = Label(master, text = "Second:")
 
# grid method to arrange labels in respective
# rows and columns as specified
l1.grid(row = 0, column = 0, sticky = W, pady = 2)
l2.grid(row = 1, column = 0, sticky = W, pady = 2)
 
# entry widgets, used to take entry from user
e1 = Entry(master)
e2 = Entry(master)
 
# this will arrange entry widgets
e1.grid(row = 0, column = 1, pady = 2)
e2.grid(row = 1, column = 1, pady = 2)
 
# infinite loop which can be terminated by keyboard
# or mouse interrupt
mainloop()
Comment

PREVIOUS NEXT
Code Example
Python :: pandas get outliers 
Python :: root.iconbitmap 
Python :: python timer() 
Python :: add image pptx python 
Python :: python zip() 
Python :: fetch data from excel in python 
Python :: python longest list in list 
Python :: Returns a new DataFrame omitting rows with null values 
Python :: append data at the end of an excel sheet pandas 
Python :: Python program to print negative numbers in a list 
Python :: Create a single executable from a Python project 
Python :: how to set and run flask app on terminal 
Python :: pip not downlaoding cryptography wheel macos 
Python :: making a return from your views 
Python :: python async function 
Python :: python split string into floats 
Python :: pandas replace non numeric values with 0? 
Python :: import tsv as dataframe python 
Python :: python pandas shift last column to first place 
Python :: python count character occurrences 
Python :: flask print request headers 
Python :: concatenate two tensors pytorch 
Python :: python turtle 
Python :: pandas groupby values in list 
Python :: python .nlargest 
Python :: pandas row sum 
Python :: duplicate in list 
Python :: splitting column values in pandas 
Python :: flask authentication user without database 
Python :: python list Clear the list content 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =