Chapter 9 GUI Programming Using Tkinter

2y ago
22 Views
2 Downloads
2.45 MB
76 Pages
Last View : 13d ago
Last Download : 3m ago
Upload by : Wren Viola
Transcription

Chapter 9GUI Programming Using Tkinter Copyright 2012 by Pearson Education, Inc. All Rights Reserved.1

Text-based User InterfacesText-based user interfaces (TUI) is a user interface that usestext, symbols, and colors. It runs in a character-based terminal.alternately called terminal user interfaces, or a characterbased user interfaces to reflect a dependence upon the propertiesof computer terminals.Like GUIs, they may use the entire screen area andaccept mouse and other inputs. They may also use color andoften structure the display using special graphical characterssuch as and , referred to in Unicode as the "box drawing"set.The modern context of use is usually a terminal emulator. Copyright 2012 by Pearson Education, Inc. All Rights Reserved.2

Text-based User Interfaces Copyright 2012 by Pearson Education, Inc. All Rights Reserved.3

Types of text terminalsFrom text application's point of view, a text screen (and communications with it)can belong to one of three types (here ordered in order of decreasing accessibility):A genuine text mode display, controlled by a video adapter or the centralprocessor itself. This is a normal condition for a locally running application onvarious types of personal computers and mobile devices. If not deterred bythe operating system, a smart program may exploit the full power of ahardware text mode.A text mode emulator. Examples are xterm for X Window System and win32console (in a window mode) for Microsoft Windows. This usually supportsprograms which expect a real text mode display, but may run considerablyslower. Certain functions of an advanced text mode, such as anown font uploading, almost certainly become unavailable.A remote text terminal. The communication capabilities usually becomereduced to a serial line or its emulation, possibly with few ioctl()s as an out-ofband channel in such cases as Telnet and Secure Shell. This is the worst case,because software restrictions hinder the use of capabilities of a remote displaydevice. Copyright 2012 by Pearson Education, Inc. All Rights Reserved.4

MS-DOS command-line interfaceMS-DOS was the main operating system for IBM PC compatible personal computers duringthe 1980sOn IBM Personal Computers and compatibles, the Basic Input Output System (BIOS) andDOS system calls provide a way to write text on the screen. Copyright 2012 by Pearson Education, Inc. All Rights Reserved.5

Microsoft Windowscommand-line interfaceAll versions of Microsoft Windows have had anMS-DOS-like command-line interface (CLI) calledCommand Prompt. This could run many DOS andvariously Win32, OS/2 1.x and POSIX commandline utilities in the same command-line session,allowing piping between commands Copyright 2012 by Pearson Education, Inc. All Rights Reserved.6

Terminal EmulatorsTerminal emulators replicate the functionality of atraditional computer terminal to provide users withaccess to a local or distant host. The emulatorpresents a terminal window to appear as though itis directly connected to the client. Most terminalemulators are designed for specific uses andfunction only with specific operating systems.Companies use these tools to access data andprograms on remote devices, servers, ormainframes. Copyright 2012 by Pearson Education, Inc. All Rights Reserved.7

Graphical User Interface (GUI)The graphical user interfaceis a form of user interfacethat allows users to interactwith electronic devicesthrough graphical icons orelements instead of textbased user interfaces.GUIs were introduced inreaction to the perceivedsteep (high) learning curveof command-line interfaces(CLIs) which requirecommands to be typed on acomputer keyboard.The actions in a GUI areusually performed throughdirect manipulation of thegraphical elements. Copyright 2012 by Pearson Education, Inc. All Rights Reserved.8

GUIsThe precursor to GUIswas invented byresearchers at theStanford ResearchInstitute, led byDouglas Engelbart.They developed the useof text-basedhyperlinks manipulatedwith a mouse (1963).In 1983, the Apple Lisawas first GUI offering. Copyright 2012 by Pearson Education, Inc. All Rights Reserved.9

GUIsThe X WindowsSystem wasintroduced in themid-1980s toprovide graphicalsupport for unixoperating systems.Microsoft introducedA Windows 1.0 in1985 Copyright 2012 by Pearson Education, Inc. All Rights Reserved.10

GUIsThe GUIs familiar to most people today are– Microsoft Windows,– Mac OS X, and– the X Window System interfaces for desktopand laptop computers in Unix based systems,– Android, Windows Phone, and Apple's iOS forhandheld ("smartphone") devices. Copyright 2012 by Pearson Education, Inc. All Rights Reserved.11

GUI programming in PythonPython has a huge number of GUIframeworks (or toolkits) available forit,from Tkinter (traditionally bundled withPython, using Tk) to a number of othercross-platform solutions, as well as bindingsto platform-specific technologies. Copyright 2012 by Pearson Education, Inc. All Rights Reserved.12

Python GUI FrameworksPyQT: PyQT is one of the favouredcross-platform Python bindingsimplementing the Qt library for the Qt(owned by Nokia) applicationdevelopment framework. Currently,PyQT is available for Unix/Linux,Windows, Mac OS X and SharpZaurus. It combines the best of Pythonand Qt and it up to the programmer todecide whether to create a program bycoding or using Qt Designer to createvisual dialogs.It is available in both, commercial aswell as GPL license. Although somefeatures may not be available in thefree version, if your application isopen source, then you can use it underthe free license.Resource: i-frameworks-for-developers/ Copyright 2012 by Pearson Education, Inc. All Rights Reserved.13

Python GUI FrameworksKivy : Kivy is anOpenGL ES 2accelerated frameworkfor the creation of newuser interfaces. Itsupports multipleplatforms namelyWindows, MacOSX,Linux, Android iOS andRaspberry Pi. It is opensource and comes withover 20 widgets in itstoolkit. Copyright 2012 by Pearson Education, Inc. All Rights Reserved.14

Python GUI FrameworksWxPython : WxPython is an open source wrapper for cross-platform GUIlibrary WxWidgets (earlier known as WxWindows) and implemented as aPython extension module. With WxPython you as a developer can createnative applications for Windows, Mac OS and Unix. If you’re just beginningto develop applications in WxPython, here is a good simple tutorial you can gothrough.PyGUI : PyGUI is a graphical application cross-platform framework for Unix,Macintosh and Windows. Compared to some other GUI frameworks, PyGUI isby far the simplest and lightweight of them all, as the API is purely in syncwith Python.PyGUI inserts very less code between the GUI platform andPython application, hence the display of the application usually displays thenatural GUI of the platform.PySide: PySide is a free and cross-platform GUI toolkit Qt initiated andsponsored by Nokia, Qt is a UI framework and a cross-platform application.PySide currently supports Linux/X11, Mac OS X, Maemo and Windows and,support for Android is in the plans for the near future.PySide provides tools toworks with multimedia, XML documents, network, databases and GUI. A keyfeature of PySide is its API compatibility with PyQt4, so if you wish tomigrate to PySide then the process will be hassle-free.For a complete list: http://wiki.python.org/moin/GuiProgramming Copyright 2012 by Pearson Education, Inc. All Rights Reserved.15

Python GUI FrameworksTkinter: Tkinter is the mostpopular programming package forgraphical user interface or desktopapps. It is so named because of itssimplicity. Tkinter is thecombination of Tk and Python'sstandard GUI framework.TKinter comes with an abundanceof resources of codes andreference books which is the majormerit of choosing it as a package.It provides diverse widgets, suchas labels, buttons, and text boxesused in a graphical user interfaceapplication. The Button controlalso called widgets are used todisplay buttons in developedapplication while the Canvaswidget is used to draw shapes(lines, ovals, polygon.) in yourapplication. Copyright 2012 by Pearson Education, Inc. All Rights Reserved.16

MotivationsWe will learn Tkinter.Tkinter is not only a useful tool fordeveloping GUI projects, but also a valuablepedagogical tool for learning object-orientedprogramming. Copyright 2012 by Pearson Education, Inc. All Rights Reserved.17

Tkinter ProgrammingTkinter is the standard GUI library for Python. Python whencombined with Tkinter provides a fast and easy way to createGUI applications. Tkinter provides a powerful object-orientedinterface to the Tk GUI toolkit.Tkinter (pronounced tea-kay-inter) is the Python interface to Tk,the GUI toolkit for Tcl/Tk.Tcl (pronounced "tickle" and is an acronym for Tool CommandLanguage) is a popular scripting language in the domains ofembedded applications, testing, prototyping, and GUIdevelopment. Tk on the other hand is an open source,multiplatform widget toolkit that is used by many differentlanguages for building GUI programs.The Tkinter interface is implemented as a Python module,tkinter.py, which is just a wrapper around a C-extension thatuses Tcl/Tk libraries. Copyright 2012 by Pearson Education, Inc. All Rights Reserved.18

Tkinter Programming : Widgetstkinter is one of the libraries which provides a number ofgraphical components to implement GUI based programs.They are called widgets.Widgets are standard graphical user interface (GUI)elements like butons, labels, textboxes.In a GUI program, there is a window with various graphicalwidgets/components with which the user can interact.Widgets are basic building blocks of a GUI application.Over the years, several widgets became a standard in alltoolkits on all OS platforms; for example a button, a checkbox or a scroll bar. Some of them might have differentnames. For instance, a check box is called a check button inTkinter.Tkinter has a small set of widgets which cover basicprogramming needs. More specialised widgets can becreated as custom widgets.Widgets are something like elements in the HTML. Youwill find different types of widgets to the different types ofelements in the Tkinter. Copyright 2012 by Pearson Education, Inc. All Rights Reserved.19

Tkinter Programming : WidgetsButton: The Button widget is used to display buttons in yourapplication.Canvas: The Canvas widget is used to draw shapes, such aslines, ovals, polygons and rectangles, in your application.Checkbutton: The Checkbutton widget is used to display anumber of options as checkboxes. The user can select multipleoptions at a time.Entry: The Entry widget is used to display a single-line textfield for accepting values from a user.https://www.tutorialspoint.com/python/python gui programming.htm Copyright 2012 by Pearson Education, Inc. All Rights Reserved.20

Tkinter Programming : WidgetsFrame: The Frame widget is used as a container widget toorganize other widgets.Label: The Label widget is used to provide a single-linecaption for other widgets. It can also contain images.Listbox: The Listbox widget is used to provide a list of optionsto a user. Copyright 2012 by Pearson Education, Inc. All Rights Reserved.21

Tkinter Programming : WidgetsMenubutton: The Menubutton widget is used to display menus inyour application.Menu: The Menu widget is used to provide various commands to auser. These commands are contained inside Menubutton.Message: The Message widget is used to display multiline textfields for accepting values from a user.Radiobutton: The Radiobutton widget is used to display a numberof options as radio buttons. The user can select only one option at atime.https://www.tutorialspoint.com/python/python gui programming.htm Copyright 2012 by Pearson Education, Inc. All Rights Reserved.22

Tkinter Programming : WidgetsScale: The Scale widget is used to provide a slider widget.Scrollbar: The Scroll

the GUI toolkit for Tcl/Tk. Tcl (pronounced "tickle" and is an acronym for Tool Command Language) is a popular scripting language in the domains of embedded applications, testing, prototyping, and GUI development. Tk on the other hand is an open source, multiplatform widget toolkit that is used by many different languages for building GUI programs.

Related Documents:

Part One: Heir of Ash Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16 Chapter 17 Chapter 18 Chapter 19 Chapter 20 Chapter 21 Chapter 22 Chapter 23 Chapter 24 Chapter 25 Chapter 26 Chapter 27 Chapter 28 Chapter 29 Chapter 30 .

layout and the components of the GUI Changes to this file are made in the Layout Editor - .m file - contains the code that controls the GUI You can program the callbacks in this file using the M-file Editor 28 Creating a GUI Typical stages of creating a GUI are: 1. Designing the GUI 2. Laying out the GUI - Using the Layout Editor 3.

TO KILL A MOCKINGBIRD. Contents Dedication Epigraph Part One Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Part Two Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16 Chapter 17 Chapter 18. Chapter 19 Chapter 20 Chapter 21 Chapter 22 Chapter 23 Chapter 24 Chapter 25 Chapter 26

In Java, GUI programming is object-oriented programming. This chapter covers the basics of GUI programming. The discussion will continue in Chap-ter 12 with more details and with more advanced techniques. 6.1 The Basic GUI Application There are two basic types of GUI program in Java: stand-alone applications and applets.

DEDICATION PART ONE Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 PART TWO Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16 Chapter 17 Chapter 18 Chapter 19 Chapter 20 Chapter 21 Chapter 22 Chapter 23 .

User Interface Programming in C#: Basics and Events Chris North CS 3724: HCI GUI Development: Goals 1. General GUI pro grammin concepts GUI components, layouts Event-based programming Graphics D irec tM a npul o,Am MVC architectures Data-driven UIs 2. C#, .NET Windows Forms Events, delegates GDI Threads .

Java GUI libraries Swing: the main Java GUI library – Benefits: Features; cross-platform compatibility; OO design – Paints GUI controls itself pixel-by-pixel Does not delegate to OS’s window system Abstract Windowing Toolkit (AWT): Sun's initial GUI library – Maps Java code to each operating system's real GUI system

No change in API which Apps refer to Apps can use API of each GUI-lib. Each GUI-lib has layer to adapt to PF Can have many different GUI-libs without change of PF. HMI Apps App FW Layer Service Layer AppLayer GUI-library GUI-lib PAL(*) ForAGL PF *PF Adaptation Layer HMI-Server (e.g.