Python programming GUI



Similar documents
Rapid GUI Application Development with Python

The wxpython tutorial

Python Crash Course: GUIs with Tkinter

S A M P L E C H A P T E R

GUI application set up using QT designer. Sana Siddique. Team 5

Python programming Testing

Mobile application development with QML & PySide

Building a Python Plugin

Scientific Visualization with wxpython and Matplotlib. Scott Pearse CSCI 5448 Spring 2011

Multiprocess System for Virtual Instruments in Python

Adding A Student Course Survey Link For Fully Online Courses Into A Canvas Course

Python programming Debugging

Fireworks 3 Animation and Rollovers

KIVY - A Framework for Natural User Interfaces

PharmaClik POS Overview

edgebooks Quick Start Guide 4

Chaco: A Plotting Package for Scientists and Engineers. David C. Morrill Enthought, Inc.

User Manual Microsoft Dynamics AX Add-on LabAX Label Printing

Rapid Application Development with GNOME and Python

Your Salesforce account has 100 free Force.com licenses that you can activate to run thirdparty applications such as DreamTeam.

I don t intend to cover Python installation, please visit the Python web site for details.

RSW. Responsive Fullscreen WordPress Theme

Image Management Suite. Mini Thesis. Roland Foster. Supervisors: Mr. Mehrdad Ghaziasgar and Mr. James Connan. B.Sc. Honours

David Boddie. PyCon UK 2007, Birmingham

HTML Form Widgets. Review: HTML Forms. Review: CGI Programs

Click on various options: Publications by Wizard Publications by Design Blank Publication

State of Michigan Data Exchange Gateway. Web-Interface Users Guide

Some programming experience in a high-level structured programming language is recommended.

PyQt for Desktop and Embedded Devices

Mac OS X. A Brief Introduction for New Radiance Users. Andrew McNeil & Giulio Antonutto

2010 Ing. Punzenberger COPA-DATA GmbH. All rights reserved.

Employee Schedule. Visual Retail Plus POS Software System. Using Employee Schedule to Effectively Track Hours & Sales.

OpenCobolIDE Documentation

How To Add The WebReserv Booking Calendar To Your Facebook Page

Create a new file/canvas to work with by going to the file menu and selecting new.

Smart Connection 9 Element Labels

Creating Appointment Groups using Scheduler

How to Add Social Media Icons to Your Website

Creating Web Pages with Microsoft FrontPage

Using Flow Control with the HEAD Recorder

Quickly Creating Professional Looking Application Using wxpython, py2exe and InnoSetup. Miki Tebeka

Surface and Volumetric Data Rendering and Visualisation

Table of Contents. Real Magnet netforum Integration User s Guide

XRD CONVERSION USER S MANUAL

Microsoft Word 2010 Tutorial

Hands-On Lab. Building a Data-Driven Master/Detail Business Form using Visual Studio Lab version: Last updated: 12/10/2010.

GR A universal framework for visualization applications

3 IDE (Integrated Development Environment)

Neutron Science Visualization Software

Statgraphics Getting started

ELFRING FONTS UPC BAR CODES

Initial Setup of Microsoft Outlook with Google Apps Sync for Windows 7. Initial Setup of Microsoft Outlook with Google Apps Sync for Windows 7

Getting Started: Creating a Simple App

LP1000N. Software Manual PLU Management Label Editor. Date: 22-NOV Support Model. Version

Introduction to the TI Connect 4.0 software...1. Using TI DeviceExplorer...7. Compatibility with graphing calculators...9

Andreas Schreiber

for Sage 100 ERP Paperless Office Overview Document

QT9 Quality Management Software

Writing standalone Qt & Python applications for Android

Microsoft Excel 2013: Macro to apply Custom Margins, Titles, Gridlines, Autofit Width & Add Macro to Quick Access Toolbar & How to Delete a Macro.

Google Merchant Center

Investigating Relationships of Area and Perimeter in Similar Polygons

TUTORIAL 4 Building a Navigation Bar with Fireworks

Creating a Poster in PowerPoint A. Set Up Your Poster

Module 1. 4 Login-Send Message to Teacher

CUSTOMER+ PURL Manager

This is a training module for Maximo Asset Management V7.1. It demonstrates how to use the E-Audit function.

Programming Mobile Apps with Python

FAQs. How do I remove the search bar completely?

A short introduction to GUI programming with the MVC concept using wxwindows

Aura: A Multi-Featured Programming Framework in Python

Faculty Web Site with WCM

Programming in Python. Basic information. Teaching. Administration Organisation Contents of the Course. Jarkko Toivonen. Overview of Python

This manual assumes you already have Precurio installed and configured appropriately.

Microsoft Word 2013 Tutorial

FREE FALL. Introduction. Reference Young and Freedman, University Physics, 12 th Edition: Chapter 2, section 2.5

Netop Remote Control for Linux Installation Guide Version 12.22

USING MYWEBSQL FIGURE 1: FIRST AUTHENTICATION LAYER (ENTER YOUR REGULAR SIMMONS USERNAME AND PASSWORD)

ACCESS 2007 BASICS. Best Practices in MS Access. Information Technology. MS Access 2007 Users Guide. IT Training & Development (818)

Python Documentation & Startup

Microsoft Excel Basics

GEIGER COUNTER "Gamma Check Pro"

Task Scheduler. Morgan N. Sandquist Developer: Gary Meyer Reviewer: Lauri Watts

This training module reviews the CRM home page called the Dashboard including: - Dashboard My Activities tab. - Dashboard Pipeline tab

OPERATION MANUAL. MV-410RGB Layout Editor. Version 2.1- higher

Inventory CheckOut and Store Manager User s Guide

Working With Direct Deposit Accounts and Your Payment Elections

Egnyte for Salesforce v2.1 Administrator s Guide

Active Directory Integration for Greentree

Company Setup 401k Tab

Slides from INF3331 lectures - web programming in Python

Rich Internet Applications

Hello. What s inside? Ready to build a website?

IFAS 7i Department Accounts Payable

Transcription:

Finn Årup Nielsen Department of Informatics and Mathematical Modelling Technical University of Denmark October 1, 2012

Graphical user interface Tk Python module Tkinter. Quick and dirty. (Langtangen, 2005, Chapters 6 & 11) wxwidgets (wxwindows) wxpython (Ubuntu package python-wxtools) and PythonCard (Ubuntu metapackage pythoncard) Others PyGTK for Gtk, PyQT and PySide for Qt Finn Årup Nielsen 1 October 1, 2012

Tkinter Hello world from Tkinter import * def hello(): """Callback function for button press.""" print "Hello World" # Main root window root = Tk() # A button with a callback function Button(root, text="press here", command=hello).pack() #.pack() method is necessary to make the button appear # Event loop root.mainloop() Finn Årup Nielsen 2 October 1, 2012

Tkinter Hello world Finn Årup Nielsen 3 October 1, 2012

Tkinter: menu, label Build a GUI for showing one tweet stored in a Mongo database. tweets at a time. One from Tkinter import * import pymongo, re pattern = re.compile(r \brt\b, re.unicode) Should read from the Mongo database, and display some of the fields in a graphical user interface. With a button the user should be able to click to the next item. Finn Årup Nielsen 4 October 1, 2012

A callback function counter = 0 def next(event=none): """Function that can be used as a callback function from a button.""" global counter # Global variable not so pretty counter += 1 tweet = tweets.find_one(skip=counter) # pymongo function while tweet.has_key( delete ) or not pattern.search(tweet["text"]): counter += 1 tweet = tweets.find_one(skip=counter) # Set gui texts gui_user["text"] = tweet["user"]["name"] gui_language["text"] = tweet["user"]["lang"] gui_followers["text"] = tweet["user"]["followers_count"] gui_text["text"] = tweet["text"] Finn Årup Nielsen 5 October 1, 2012

Initial setup of window root = Tk() # Title of the window root.title( Twitter in Mongo GUI ) # key associated with the next callback function root.bind( n, next) # Build menubar menubar = Menu(root) filemenu = Menu(menubar, tearoff=0) filemenu.add_command(label="exit", command=root.destroy) menubar.add_cascade(label="file", menu=filemenu) # Get Mongo collection of tweets tweets = pymongo.connection().twitter.tweets Finn Årup Nielsen 6 October 1, 2012

Set up of window components # Using a Frame to contain two Label s in a row frame = Frame(root) Label(frame, text="user:", width=10).pack(side=left) gui_user = Label(frame) gui_user.pack(side=left) frame.pack(fill=x) frame = Frame(root) Label(frame, text="language:", width=10).pack(side=left) gui_language = Label(frame) gui_language.pack(side=left) frame.pack(fill=x) frame = Frame(root) Label(frame, text="followers:", width=10).pack(side=left) Finn Årup Nielsen 7 October 1, 2012

gui_followers = Label(frame) gui_followers.pack(side=left) frame.pack(fill=x) frame = Frame(root) Label(frame, text="text:", width=10).pack(side=left) gui_text = Label(frame) gui_text.pack(side=left) frame.pack(fill=x) # Next button frame = Frame(root) Button(frame, text="next", width=8, command=next).pack(side=left) frame.pack(fill=x) root.config(menu=menubar) root.mainloop() Finn Årup Nielsen 8 October 1, 2012

Rendered window Finn Årup Nielsen 9 October 1, 2012

New next button Brent Burley (Martelli et al., 2005, pages 432 434) import base64 # Load a GIF file with an appropriate icon image icon = base64.encodestring(open( Billeder/right.gif ).read()) # Once you have read the GIF you can put the string in the code iconimage = PhotoImage(master=root, data=icon) Button(frame, image=iconimage, command=next).pack(side=left) Finn Årup Nielsen 10 October 1, 2012

Tkinter canvas Drawing in the Tkinter interface with canvas. Example from (Langtangen, 2005, pages 527+) from Tkinter import * root = Tk() canvas = Canvas(root, width=400, height=200) canvas.pack() canvas.create_oval(10, 10, 110, 60, fill="grey") canvas.create_text(60, 35, text="oval") canvas.create_rectangle(10, 100, 110, 150, outline="blue") canvas.create_text(60, 125, text="rectangle") canvas.create_line(60, 60, 60, 100, width=3) Finn Årup Nielsen 11 October 1, 2012

Mouse callback class MouseMover(): def init (self): self.item = 0; self.previous = (0, 0) def select(self, event): widget = event.widget # Get handle to canvas # Convert screen coordinates to canvas coordinates xc = widget.canvasx(event.x); yc = widget.canvasx(event.y) self.item = widget.find_closest(xc, yc)[0] # ID for closest self.previous = (xc, yc) print((xc, yc, self.item)) def drag(self, event): widget = event.widget xc = widget.canvasx(event.x); yc = widget.canvasx(event.y) canvas.move(self.item, xc-self.previous[0], yc-self.previous[1]) self.previous = (xc, yc) Finn Årup Nielsen 12 October 1, 2012

Canvas with mouse callback # Get an instance of the MouseMover object mm = MouseMover() # Bind mouse events to methods (could also be in the constructor) canvas.bind("<button-1>", mm.select) canvas.bind("<b1-motion>", mm.drag) Finn Årup Nielsen 13 October 1, 2012

wxpython http://www.wxpython.org import wx # Must always be set app = wx.app() # A window frame = wx.frame(none, title="hello, World") frame.show() # Event loop app.mainloop() Finn Årup Nielsen 14 October 1, 2012

wx: event, get, set import wx app = wx.app() class Incrementor(wx.Frame): def init (self, parent, id, title="window"): wx.frame. init (self, parent, id, title, size=(400, 200)) wx.statictext(self, -1, Input:, (60, 100)) self.edit = wx.textctrl(self, value="0", pos=(100, 95), size=(200, 30)) forward_button = wx.button(self, -1, >, pos=(185, 170), size=(30, 30) self.bind(wx.evt_button, self.forward, id=forward_button.getid()) self.centre() # Center in the middle of the screen self.show(true) def forward(self, event): try: self.edit.setvalue(str(int(self.edit.getvalue())+1)) except: pass Incrementor(None, -1); app.mainloop() Finn Årup Nielsen 15 October 1, 2012

Python GTK Gwibber: social network client written in Python and using the GTK module. Finn Årup Nielsen 16 October 1, 2012

What to choose? Tkinter. De-facto standard GUI. May be included in standard install. Probably good for simple applications. $ less /usr/lib/pymodules/python2.7/nltk/downloader.py PyGTK (LGPL). Used in a range of programs on the Linux system. Gwibber, jokosher, update-manager,... : $ less which update-manager PyQT (GPL) for QT. PySide (LGPL) for QT. Sponsored by Nokia. wxpython Finn Årup Nielsen 17 October 1, 2012

References References Langtangen, H. P. (2005). Python Scripting for Computational Science, volume 3 of Texts in Computational Science and Engineering. Springer. ISBN 3540294155. Martelli, A., Ravenscroft, A. M., and Ascher, D., editors (2005). Python Cookbook. O Reilly, Sebastopol, California, 2nd edition. Finn Årup Nielsen 18 October 1, 2012