Width Height Fill Expand Weight Weight: Scrollbar: Import As

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Scrollbar :

import tkinter as tk

root = tk.Tk()

frame = tk.Frame(root, width=300, height=300)


frame.pack(fill="both", expand=True)
frame.grid_rowconfigure(0, weight=1)
frame.grid_columnconfigure(0, weight=1)

# create a Text widget


txt = tk.Text(frame, borderwidth=4, relief="sunken")
txt.config(font=("Arial", 12), undo=True, wrap='word')
txt.grid(row=0, column=0, sticky="nsew", padx=2, pady=2)

# create a Scrollbar and associate it with txt


sc = tk.Scrollbar(frame, command=txt.yview)

'''sticky − What to do if the cell is larger than widget.


By default, with sticky='', widget is centered in its cell.
sticky may be the string concatenation of zero or more of N, E, S, W, NE, NW, SE,
and SW, compass
directions indicating the sides and corners of the cell to which widget sticks.'''
sc.grid(row=0, column=1, sticky='nsew')
txt['yscrollcommand'] = sc.set

root.mainloop()

ListScrollbar:
from tkinter import *

root = Tk()
scrollbar = Scrollbar(root)
#scrollbar should stretch to fill any extra space in the y axis ( fill="y" )
scrollbar.pack( side = RIGHT, fill = Y )

#To connect a vertical scrollbar to such a widget, you have to do two things:

#Set the widget’s yscrollcommand callbacks to the set method of the scrollbar.

#Set the scrollbar’s command to the yview method of the widget.


mylist = Listbox(root, yscrollcommand = scrollbar.set )
for line in range(100):
mylist.insert(END, "This is line number " + str(line))

mylist.pack( side = LEFT, fill = BOTH )


scrollbar.config( command = mylist.yview )

mainloop()

Listbox:
from tkinter import *

root = Tk()
scrollbar = Scrollbar(root)
#scrollbar should stretch to fill any extra space in the y axis ( fill="y" )
scrollbar.pack( side = RIGHT, fill = Y )

#To connect a vertical scrollbar to such a widget, you have to do two things:

1
#Set the widget’s yscrollcommand callbacks to the set method of the scrollbar.

#Set the scrollbar’s command to the yview method of the widget.


mylist = Listbox(root, yscrollcommand = scrollbar.set )
for line in range(100):
mylist.insert(END, "This is line number " + str(line))

mylist.pack( side = LEFT, fill = BOTH )


scrollbar.config( command = mylist.yview )

mainloop()

Relief :
from tkinter import *
import tkinter

top = Tk()

B1 = Button(top, text ="FLAT", relief=FLAT )


B2 = Button(top, text ="RAISED", relief=RAISED )
B3 = Button(top, text ="SUNKEN", relief=SUNKEN )
B4 = Button(top, text ="GROOVE", relief=GROOVE )
B5 = Button(top, text ="RIDGE", relief=RIDGE )

B1.pack()
B2.pack()
B3.pack()
B4.pack()
B5.pack()
top.mainloop()

You might also like