This Week: Tkinter for GUI Interfaces Some examples

Slides:



Advertisements
Similar presentations
Tk. Toolkit n Wish - windowing shell –touch fileName –chmod +x fileName –xedit fileName & –#!/usr/local/bin/wish n Widgets - eg Buttons, Labels, Frames.
Advertisements

Tk Widgets This material is best on several sources –Slides by Dr. Ernest J. Friedman-Hill –various Tcl/Tk books.
What is a Dialog box? A Dialog box is a window or “form” that contains other child windows or “controls” that have a specific appearances and pre-defined.
Intermediate Level Course. Text Format The text styles, bold, italics, underlining, superscript and subscript, can be easily added to selected text. Text.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Introduction To Form Builder
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
WEEK Introduction to GUI programming. Introduction Each data type can represent a certain set of values, and each had a set of associated operations.
COMPSCI 101 Principles of Programming
18. Python - GUI Programming (Tkinter)
Chapter 12: Using Controls. Examining the IDE’s Automatically Generated Code A new Windows Forms project has been started and given the name FormWithALabelAndAButton.
Tcl/Tk package in R Yichen Qin
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
The University of Texas – Pan American
Guide to Programming with Python Chapter Ten GUI Development: The Mad Lib Program.
PYTHON GUI PROGRAMMING
Working with Objects. Objectives Create an object Transform an object Arrange and lock an object Step and repeat an object Use Live Distribute Use the.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 20 Graphical User Interface (GUI)
Python Programming Graphical User Interfaces Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 9 GUI Programming Using Tkinter 1.
How the Session Works Outline Practical on arrival Talk 1 Reflect on practical Clarify concepts Practical exercises at your own pace Talk 2: Further concepts.
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
SEEM3460 Tutorial GUI in Java. Some Basic GUI Terms Component (Control in some languages) the basic GUI unit something visible something that user can.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
Tkinter Basics. Initial Stuff To get the package: from tkinter import * To make a window, give it a title and operate it: windowVar = Tk() windowVar.title(“your.
Graphics Programming with Python. Many choices Python offers us several library choices:  Tkinter  WxPython  PyQt  PyGTK  Jython  And others...
Creating visual interfaces in python
CMPF114 Computer Literacy Chapter 3 The Visual Basic Environment 1.
Video in Macromedia Flash (Optional) – Lesson 121 Video in Macromedia Flash (Optional) Lesson 12.
Guide to Programming with Python
PowerBuilder Window Window Controls Window Properties Window Types
COMPSA Exam Prep Session by Paul Allison On: April 8th from 1:30-3:00 Location TBA Winter 2016CISC101 - Prof. McLeod1.
See Winter 2016CISC101 - Prof. McLeod1.
COMPSA Exam Prep Session On: April 8th from 1:30-3:00 Location TBA Winter 2016CISC101 - Prof. McLeod1.
LEARN TO FORMAT TABLES Unit 10: Lessons What is a Table? ◦ A table is an arrangement of data (words and/or numbers) in rows and columns. ◦ A table.
DB Implementation: MS Access Forms. MS Access Forms: Purpose Data entry, editing, & viewing data in Tables Forms are user-friendlier to end-users than.
Innovation Intelligence ® Feb Copyright © 2012 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved. GUI design Controls Toplevel.
Tk Widgets in Javascript
Topics Graphical User Interfaces Using the tkinter Module
Microsoft Access 2007 – Level 2
Graphical User Interfaces (GUIs)
Chapter 21 – Graphics/Tk Outline 21.1 Introduction 21.2 GD Module: Creating Simple Shapes 21.3 GD Module: Image Manipulation 21.4 Chart Module 21.5 Introduction.
Chapter 8: Writing Graphical User Interfaces
Building a User Interface with Forms
Working with Tabs and Tables
Chap 7. Building Java Graphical User Interfaces
CISC101 Reminders Grading of Quiz 4 underway.
DB Implementation: MS Access Forms
GUI Using Python.
Graphical User Interfaces -- Introduction
Fundamentals of Python: From First Programs Through Data Structures
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Tkinter GUIs Computer Science and Software Engineering
IVend Retail 6.5 Dashboard Designer.
Visual Basic.
Chapter 2 – Introduction to the Visual Studio .NET IDE
AWT Components and Containers
GTK + Programming.
DB Implementation: MS Access Forms
NexTk/NtkWidget A replacement for Tk ?! 1.
Fundamentals of Programming I Windows, Labels, and Command Buttons
Topics Graphical User Interfaces Using the tkinter Module
Visual C# - GUI and controls - 1
Python – Tkinter Windows Application
The University of Texas – Pan American
Key Applications Module Lesson 14 — Working with Tables
Tkinter User Input Form
Presentation transcript:

This Week: Tkinter for GUI Interfaces Some examples Programming Training This Week: Tkinter for GUI Interfaces Some examples

Tkinter Overview Set of widgets designed by John K. Ousterhout, 1987 Tkinter == Tool Kit Interface Mean to be driven by Tcl (Toolkit Control Language) Tkinter is the Python Tcl/Tk Interface Very easy to use with few UI classes 3 ways to manage the layout geometry Simple way to deal with events

Tkinter Overview Widgets to work with: Button Canvas Checkbutton Entry The Button widget is used to display buttons in your application. Canvas The Canvas widget is used to draw shapes, such as lines, ovals, polygons and rectangles, in your application. Checkbutton The Checkbutton widget is used to display a number of options as checkboxes. The user can select multiple options at a time. Entry The Entry widget is used to display a single-line text field for accepting values from a user. Frame The Frame widget is used as a container widget to organize other widgets. Label The Label widget is used to provide a single-line caption for other widgets. It can also contain images. Listbox The Listbox widget is used to provide a list of options to a user. Menubutton The Menubutton widget is used to display menus in your application. Menu The Menu widget is used to provide various commands to a user. These commands are contained inside Menubutton.

Tkinter Overview Widgets to work with: Message Radiobutton Scale The Message widget is used to display multiline text fields for accepting values from a user. Radiobutton The Radiobutton widget is used to display a number of options as radio buttons. The user can select only one option at a time. Scale The Scale widget is used to provide a slider widget. Scrollbar The Scrollbar widget is used to add scrolling capability to various widgets, such as list boxes. Text The Text widget is used to display text in multiple lines. Toplevel The Toplevel widget is used to provide a separate window container. Spinbox The Spinbox widget is a variant of the standard Tkinter Entry widget, which can be used to select from a fixed number of values. PanedWindow A PanedWindow is a container widget that may contain any number of panes, arranged horizontally or vertically. LabelFrame A labelframe is a simple container widget. Its primary purpose is to act as a spacer or container for complex window layouts.

Tkinter Overview All widgets have some standard attributes to give the size, color, font, anchor, bitmaps etc: Dimension = various width, height, sizes of the widget expressed in pixels width, height = required sizes for the widget padx, pady = extra space the widgets asks for borderwidth = the width of the border rectangle of the widget

Tkinter Overview All widgets have some standard attributes to give the size, color, font, anchor, bitmaps etc: Color = attributes for the background, foreground etc color = given as string e.g. “white” of hexa-number “#ffffff” background or bg for the widget background foreground or fg for the widget foreground activebackground and activeforeground selectforeground and disabledforeground

Tkinter Overview One geometry manager for the layout to organise widgets with: grid method  widget takes a cell within a grid place method  widget is position to some given coords. pack method  widget is pack in the frame as it comes Simple way to work with widget.grid(row = 2, column = 1) widget.pack() widget.place(x=100, y=200)

Tkinter Example

Tkinter Example Some explanation: tkinter module is imported first. root = instance of Tk to create the UI frame label = instance of Label for the parent root to hold the text Hello Tkinter the label is then packed into root root.mainloop() deals with the frame events

Tkinter - How to? Simplest way (procedural way): Import the modules needed by the interface. Create the frame as instance of Tk() Create all the components needed in the interface Construct the component Setup some of their attributes Give their position in the layout root.mainloop()

Widgets - Label Label = box to display/change a text or an image. Constructor label = Label ( master, option, ... ) Options refer to the following: dimension, color, etc manipulating the text or the image text, image underline textvariable textvariable is needed for manipulating the label text.

Label

Widgets - Entry Entry = Widget to manipulate a single line of text. Constructor entry = Entry ( master, option, ... ) Options refer to the following: dimension, color, etc manipulating the text by textvariable show to define an echo character Various ivar methods for entry text manipulation: get()  gets all the characters delete(first, last)  deletes from first to last insert(index, word)  inserts word at the index position

Entry

Widgets - Button Button = display a text or image and to react to a click. Constructor button = Button ( master, option, ... ) Options refer to the following: dimension, color, etc command to set the callback function Two ivar methods for entry text manipulation: flash()  button will flash between states invoke()  explicit call of the button collback

Button

Widgets - Listbox Listbox = widget to display a (long) list of items from which we can select. Constructor list= Listbox( master, option, ... ) Options refer to the following: dimension, color, etc selectmode gives how we can select the items from list SINGLE  one item to select when clicked BROWSE  one item to select that drags with the mouse MULTIPLE multiple selection by toggling items

Widgets - Listbox Lots of functions to manage the listbox and its selection. Manage the list: size()  number of items in listbox delete(first, last)  delete all items between the specified first and last insert(index, *items)  insert the items from index etc Selection curselection()  returns the tuple with the selected indices.

Widgets - Listbox Listbox-es are created usually from array of items using a for loop. listbox = Listbox(root) items = [“item0”, “item1”, “item2”, “item3”, “item4”] for item in items: listbox.insert(END, item) Listbox-es do not have command however we can bind with it. listbox.bind("<<ListboxSelect>>", self.onSelect)

Example 1 - Converter Converter Euro to Dollar Interface: widgets: 2 Label-s, 2 Entry-s and 2 Button-s Additional 2 StringVar to manipulate the Entry text All widgets with a simple grid geometry Callback functions for the buttons

Example 2 – Turtle Interface Interface to control drawing Turtle figures. Widgets to work with: 2 Label-s, 2 Entry-s for the figure order and length. Additional 2 StringVar to manipulate their text. A button clear to reset everything. Some widgets, maybe buttons, to draw the required fractal

To do List Solve the HW problems. Read more about the Tkinter module