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

tkinter frames and grids

from Tkinter import *

root = Tk()
root.title('Model Definition')
root.resizable(width=FALSE, height=FALSE)
root.geometry('{}x{}'.format(460, 350))

top_frame = Frame(root, bg='cyan', width = 450, height=50, pady=3).grid(row=0, columnspan=3)
Label(top_frame, text = 'Model Dimensions').grid(row = 0, columnspan = 3)
Label(top_frame, text = 'Width:').grid(row = 1, column = 0)
Label(top_frame, text = 'Length:').grid(row = 1, column = 2)
entry_W = Entry(top_frame).grid(row = 1, column = 1)
entry_L = Entry(top_frame).grid(row = 1, column = 3)
#Label(top_frame, text = '').grid(row = 2, column = 2)

center = Frame(root, bg='gray2', width=50, height=40, padx=3, pady=3).grid(row=1, columnspan=3)
ctr_left = Frame(center, bg='blue', width=100, height=190).grid(column = 0, row = 1, rowspan = 2)
ctr_mid = Frame(center, bg='yellow', width=250, height=190, padx=3, pady=3).grid(column = 1, row=1, rowspan=2)
ctr_right = Frame(center, bg='green', width=100, height=190, padx=3, pady=3).grid(column = 2, row=1, rowspan=2)

btm_frame = Frame(root, bg='white', width = 450, height = 45, pady=3).grid(row = 3, columnspan = 3)
btm_frame2 = Frame(root, bg='lavender', width = 450, height = 60, pady=3).grid(row = 4, columnspan = 3)


root.mainloop()
Comment

PREVIOUS NEXT
Code Example
Python :: turtle graphics documentation|pensize 
Python :: how to handle missing values in dataset 
Python :: python use variable name as variable 
Python :: best scraping package in python 
Python :: What will be the output of the following program? 
Python :: sort python 
Python :: binary to octal in python 
Python :: if statement in python 
Python :: pca 
Python :: data must be 1-dimensional pd.dataframe 
Python :: pandas groupby most frequent 
Python :: how to copy the list in python 
Python :: python convert b string to dict 
Python :: excel write column 
Python :: how can I corect word spelling by use of nltk? 
Python :: isnotin python 
Python :: appending items to a tuple python 
Python :: decimal to binary python 
Python :: python find first occurrence in list 
Python :: how to make a key logger 
Python :: python curses for windows 
Python :: python if elif 
Python :: numpy reshape (n ) to (n 1) 
Python :: how to define variable in python 
Python :: how to negate a boolean python 
Python :: kdeplot python 
Python :: how to serach for multiple attributes in xpath selenium python 
Python :: list to dictionary 
Python :: nltk 
Python :: plot matrix as heatmap 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =