Advance Python Unit - 1
Advance Python Unit - 1
1 Button
The Button widget is used to display buttons in your application.
2 Canvas
The Canvas widget is used to draw shapes, such as lines, ovals, polygons and rectangles, in
your application.
3 Checkbutton
The Checkbutton widget is used to display a number of options as checkboxes. The user can
select multiple options at a time.
4 Entry
The Entry widget is used to display a single-line text field for accepting values from a user.
5 Frame
The Frame widget is used as a container widget to organize other widgets.
6 Label
The Label widget is used to provide a single-line caption for other widgets. It can also contain
images.
7 Listbox
The Listbox widget is used to provide a list of options to a user.
Method Description
# geometry method
frame.pack()
1 flash()
Causes the button to flash several times between active and normal colors.
Leaves the button in the state it was in originally. Ignored if the button is
disabled.
2 invoke()
Calls the button's callback, and returns what that function returns. Has no
effect if the button is disabled or there is no callback.
root = Tk()
root.geometry("300x200")
messagebox.showinfo("showinfo", "Information")
messagebox.showwarning("showwarning", "Warning")
messagebox.showerror("showerror", "Error")
messagebox.askquestion("askquestion", "Are you sure?")
messagebox.askokcancel("askokcancel", "Want to continue?")
messagebox.askyesno("askyesno", "Find the value?")
messagebox.askretrycancel("askretrycancel", "Try again?")
root.mainloop()
1 deselect()
Clears (turns off) the checkbutton.
2 flash()
Flashes the checkbutton a few times between its active and normal
colors, but leaves it the way it started.
3 invoke()
You can call this method to get the same actions that would occur if the
user clicked on the checkbutton to change its state.
4 select()
Sets (turns on) the checkbutton.
5 toggle()
Clears the checkbutton if set, sets it if cleared.
bottomframe = Frame(root)
bottomframe.pack( side = BOTTOM )
root.mainloop()
top = Tk()
Lb1 = Listbox(top)
Lb1.insert(1, "Python")
Lb1.insert(2, "Perl")
Lb1.insert(3, "C")
Lb1.insert(4, "PHP")
Lb1.insert(5, "JSP")
Lb1.insert(6, "Ruby")
Lb1.pack()
top.mainloop()
top = Tk()
mb = Menubutton ( top, text = "GfG")
mb.grid()
mb.menu = Menu ( mb, tearoff = 0 )
mb["menu"] = mb.menu
cVar = IntVar()
aVar = IntVar()
mb.menu.add_checkbutton ( label ='Contact', variable = cVar )
mb.menu.add_checkbutton ( label = 'About', variable = aVar )
mb.pack()
top.mainloop()
root = Tk()
menu = Menu(root)
root.config(menu=menu)
filemenu = Menu(menu)
menu.add_cascade(label='File', menu=filemenu)
filemenu.add_command(label='New')
filemenu.add_command(label='Open...')
filemenu.add_separator()
filemenu.add_command(label='Exit', command=root.quit)
helpmenu = Menu(menu)
menu.add_cascade(label='Help', menu=helpmenu)
helpmenu.add_command(label='About')
mainloop()
3 invoke()
You can call this method to get the same actions that would occur if the
user clicked on the radiobutton to change its state.
4 select()
Sets (turns on) the radiobutton.
1 get()
This method returns the current value of the scale.
2 set ( value )
Sets the scale's value.
1 get()
Returns two numbers (a, b) describing the current position of the slider.
The a value gives the position of the left or top edge of the slider, for
horizontal and vertical scrollbars respectively; the b value gives the
position of the right or bottom edge.
1 delete(startindex [,endindex])
This method deletes a specific character or a range of text.
2 get(startindex [,endindex])
This method returns a specific character or a range of text.
3 index(index)
Returns the absolute value of an index based on the given index.
4 insert(index [,string]...)
This method inserts strings at the specified index location.
5 see(index)
This method returns true if the text located at the index position is
visible.
1 delete(startindex [,endindex])
This method deletes a specific character or a range of text.
2 get(startindex [,endindex])
This method returns a specific character or a range of text.
3 identify(x, y)
Identifies the widget element at the given location.
4 index(index)
Returns the absolute value of an index based on the given index.
5 insert(index [,string]...)
This method inserts strings at the specified index location.
6 invoke(element)
Invokes a spinbox button
1 add(child, options)
Adds a child window to the paned window.
2 get(startindex [,endindex])
This method returns a specific character or a range of text.
3 config(options)
Modifies one or more widget options. If no options are given, the
method returns a dictionary containing all current option values.
root.mainloop()