Python Tutorial ( PDFDrive )
CHAPTER26Python GUI ProgrammingPython provides various options for developing graphical user interfaces (GUIs). Most important are listedbelow:• Tkinter: Tkinter is the Python interface to the Tk GUI toolkit shipped with Python. We would look this optionin this tutorial.• wxPython: This is an open-source Python interface for wxWindows http://wxpython.org.• JPython: JPython is a Python port for Java which gives Python scripts seamless access to Java classlibraries on the local machine http://www.jython.org.There are many other interfaces available which I'm not listing here. You can find them over the net.Tkinter Programming Tkinter is the standard GUI library for Python. Python when combined with Tkinter provides a fast and easy wayto create GUI applications. Tkinter provides a powerful object-oriented interface to the Tk GUI toolkit.Creating a GUI application using Tkinter is an easy task. All you need to do is perform the following steps:• Import the Tkinter module.• Create the GUI application main window.• Add one or more of the above-mentioned widgets to the GUI application.• Enter the main event loop to take action against each event triggered by the user.Example: #!/usr/bin/pythonimport Tkintertop = Tkinter.Tk()# Code to add widgets will go here...top.mainloop()This would create a following window:TUTORIALS POINT Simply Easy Learning
Tkinter Widgets Tkinter provides various controls, such as buttons, labels and text boxes used in a GUI application. Thesecontrols are commonly called widgets.There are currently 15 types of widgets in Tkinter. We present these widgets as well as a brief description in thefollowing table:OperatorButtonCanvasCheckbuttonEntryFrameLabelListboxMenubuttonMenuMessageRadiobuttonScaleDescriptionThe Button widget is used to display buttons in your application.The Canvas widget is used to draw shapes, such as lines, ovals, polygons and rectangles, inyour application.The Checkbutton widget is used to display a number of options as checkboxes. The user canselect multiple options at a time.The Entry widget is used to display a single-line text field for accepting values from a user.The Frame widget is used as a container widget to organize other widgets.The Label widget is used to provide a single-line caption for other widgets. It can also containimages.The Listbox widget is used to provide a list of options to a user.The Menubutton widget is used to display menus in your application.The Menu widget is used to provide various commands to a user. These commands arecontained inside Menubutton.The Message widget is used to display multiline text fields for accepting values from a user.The Radiobutton widget is used to display a number of options as radio buttons. The user canselect only one option at a time.The Scale widget is used to provide a slider widget.TUTORIALS POINT Simply Easy Learning
- Page 317 and 318: Data Hiding: An object's attribute
- Page 319 and 320: groups()This method returns all mat
- Page 321 and 322: SYNTAX: re.sub(pattern, repl, strin
- Page 323 and 324: \s Matches whitespace. Equivalent t
- Page 325 and 326: Backreferences: This matches a prev
- Page 327 and 328: CHAPTER20Python CGI ProgrammingWhat
- Page 329 and 330: If you click hello.py, then this pr
- Page 331 and 332: Simple URL Example : Get Metho
- Page 333 and 334: </form>The result of this code is t
- Page 335 and 336: text_content = form.getvalue('textc
- Page 337 and 338: Here is an example of how to retrie
- Page 339 and 340: CHAPTER21Python Database AccessThe
- Page 341 and 342: EXAMPLE: Following is the example o
- Page 343 and 344: ('Mac', 'Mohan', 20, 'M', 2000)try:
- Page 345 and 346: DELETE Operation: DELETE operation
- Page 347 and 348: ProgrammingErrorSubclass of Databas
- Page 349 and 350: The socket Module: To create a so
- Page 351 and 352: Protocol Common function Port No Py
- Page 353 and 354: Subject: SMTP e-mail testThis is a
- Page 355 and 356: try:smtpObj = smtplib.SMTP('localho
- Page 357 and 358: count = 0while count < 5:time.sleep
- Page 359 and 360: Synchronizing Threads: The threadi
- Page 361 and 362: thread = myThread(threadID, tName,
- Page 363 and 364: <stars>10</stars><description>Talk
- Page 365 and 366: print "Rating:", self.ratingelif se
- Page 367: Format: DVDRating: PGDescription: T
- Page 371 and 372: fgfontheighthighlightcolorimagejust
- Page 373 and 374: WidthXscrollincrementXscrollcommand
- Page 375 and 376: pattern when it is over the checkbu
- Page 377 and 378: The Entry widget is used to accept
- Page 379 and 380: E1 = Entry(top, bd =5)E1.pack(side
- Page 381 and 382: Optionanchorbgbitmapbdcursorfontfgh
- Page 383 and 384: selectmodeDetermines how many items
- Page 385 and 386: Syntax: Here is the simple syntax t
- Page 387 and 388: Menu The goal of this widget is to
- Page 389 and 390: filemenu.add_command(label="Exit",
- Page 391 and 392: Example: Try the following example
- Page 393 and 394: WidthWraplengthWidth of the label i
- Page 395 and 396: label appears in the top left corne
- Page 397 and 398: Parameters: • master: This repres
- Page 399 and 400: Parameters: • master: This repres
- Page 401 and 402: mark_gravity(mark [,gravity])Return
- Page 403 and 404: Methods & Descriptiondeiconify()Dis
- Page 405 and 406: disabledbackgrounddisabledforegroun
- Page 407 and 408: bgbdThe color of the slider and arr
- Page 409 and 410: fontheightlabelAnchorhighlightbackg
- Page 411 and 412: Standard attributes:Let's take a l
- Page 413 and 414: • family: The font family name as
- Page 415 and 416: B2.pack()B3.pack()B4.pack()B5.pack(
- Page 417 and 418: • "heart"• "heart"• "man"•
CHAPTER
26
Python GUI Programming
Python provides various options for developing graphical user interfaces (GUIs). Most important are listed
below:
• Tkinter: Tkinter is the Python interface to the Tk GUI toolkit shipped with Python. We would look this option
in this tutorial.
• wxPython: This is an open-source Python interface for wxWindows http://wxpython.org.
• JPython: JPython is a Python port for Java which gives Python scripts seamless access to Java class
libraries on the local machine http://www.jython.org.
There are many other interfaces available which I'm not listing here. You can find them over the net.
Tkinter Programming
Tkinter is the standard GUI library for Python. Python when combined with Tkinter provides a fast and easy way
to create GUI applications. Tkinter provides a powerful object-oriented interface to the Tk GUI toolkit.
Creating a GUI application using Tkinter is an easy task. All you need to do is perform the following steps:
• Import the Tkinter module.
• Create the GUI application main window.
• Add one or more of the above-mentioned widgets to the GUI application.
• Enter the main event loop to take action against each event triggered by the user.
Example:
#!/usr/bin/python
import Tkinter
top = Tkinter.Tk()
# Code to add widgets will go here...
top.mainloop()
This would create a following window:
TUTORIALS POINT
Simply Easy Learning