CSE : Python Programming

Similar documents
CSE : Python Programming

61A Lecture 2. Friday, August 28, 2015

CSE : Python Programming

CSE : Python Programming. Packages (Tutorial, Section 6.4) Announcements. Today. Packages: Concretely. Packages: Overview

Lecture 4. Defining Functions

Lecture 3. Functions & Modules

Announcements. Lecture Agenda. Class Exercise. Hashable. Mutability. COMP10001 Foundations of Computing Iteration

Today: Revisit some objects. Programming Languages. Key data structure: Dictionaries. Using Dictionaries. CSE 130 : Winter 2009

LECTURE 2. Python Basics

Lecture 3. Functions & Modules

Programming Languages

Not-So-Mini-Lecture 6. Modules & Scripts

Python GUI programming with PySide. Speaker: BigLittle Date: 2013/03/04

Friday, 11 April 14. Advanced methods for creating decorators Graham Dumpleton PyCon US - April 2014

CS1 Lecture 13 Feb. 13, 2019

Outline. Simple types in Python Collections Processing collections Strings Tips. 1 On Python language. 2 How to use Python. 3 Syntax of Python

Programming Languages

Next: What s in a name? Programming Languages. Data model in functional PL. What s in a name? CSE 130 : Fall Lecture 13: What s in a Name?

Overview of List Syntax

Al al-bayt University Prince Hussein Bin Abdullah College for Information Technology Computer Science Department

Introduction to Python

CSE : Python Programming. Decorators. Announcements. The decorator pattern. The decorator pattern. The decorator pattern

Sequences and iteration in Python

Python for Non-programmers

Lecture 9: July 14, How to Think About Debugging

CIS192 Python Programming

Working with Lists 4

CSC108: Introduction to Computer Programming. Lecture 11

Course Outline - COMP150. Lectures and Labs

Introduction to Programming in Python (2)

CS61A Notes Week 13: Interpreters

Online Free Ebooks Download Tkinter GUI Application Development Blueprints

logstack Documentation

CS123. Programming Your Personal Robot. Part 2: Event Driven Behavior

HIGHER ORDER FUNCTIONS 2

ENVIRONMENT MODEL: FUNCTIONS, DATA 18

Lists, loops and decisions

Iterators & Generators

Python 1: Intro! Max Dougherty Andrew Schmitt

Homework notes. Homework 2 grades posted on canvas. Homework 3 due tomorrow. Homework 4 posted on canvas. Due Tuesday, Oct. 3

dypy: Dynamical Systems in Python PHY250 Project Report Spring 2008

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Widget Toolkits CS MVC

[301] Objects/References. Tyler Caraza-Harter

Worksheet 6: Basic Methods Methods The Format Method Formatting Floats Formatting Different Types Formatting Keywords

CS/ENGRD 2110 FALL Lecture 2: Objects and classes in Java

Portable GUI for ptpython shell

Lecture 9: GUI and debugging

mpl Release latest May 17, 2017

CIS192 Python Programming

MUTABLE LISTS AND DICTIONARIES 4

COMP519 Web Programming Lecture 20: Python (Part 4) Handouts

Functions, Scope & Arguments. HORT Lecture 12 Instructor: Kranthi Varala

LECTURE 17. GUI Programming

1 Lecture 7: Functions I

CSE 140 wrapup. Michael Ernst CSE 140 University of Washington

Introduction To Python Programming And Developing GUI Applications With PyQT By B. M. Harwani

CS Programming Languages: Python

Argparse Tutorial Release 2.7.9

ERTH 401 / GEOP 501 Computational Methods for Geoscientists. Lecture 04: Functions

CME 193: Introduction to Scientific Python Lecture 1: Introduction

CSE 341: Programming Languages

CSC 148 Lecture 3. Dynamic Typing, Scoping, and Namespaces. Recursion

Lecture 7. Memory in Python

CSC326 Meta Programming i. CSC326 Meta Programming

CS 11 python track: lecture 4

CSE : Python Programming. Homework 5 and Projects. Announcements. Course project: Overview. Course Project: Grading criteria

Asynchronous Programming

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Exceptions & a Taste of Declarative Programming in SQL

Lecture 4. Defining Functions

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

Notebook. March 30, 2019

Python. Jae-Gil Lee Based on the slides by K. Naik, M. Raju, and S. Bhatkar. December 28, Outline

THE PRAGMATIC INTRO TO REACT. Clayton Anderson thebhwgroup.com WEB AND MOBILE APP DEVELOPMENT AUSTIN, TX

Embedding Python in Your C Programs

CIS192: Python Programming

Crossing bridges. Crossing bridges Great Ideas in Theoretical Computer Science. Lecture 12: Graphs I: The Basics. Königsberg (Prussia)

Intro. Scheme Basics. scm> 5 5. scm>

University of Washington CSE 140 Introduction to Data Programming Winter Midterm exam. February 6, 2013

GUI in C++ PV264 Advanced Programming in C++ Nikola Beneš Jan Mrázek Vladimír Štill. Faculty of Informatics, Masaryk University.

Lecture 3 - Overview. More about functions Operators Very briefly about naming conventions Graphical user interfaces (GUIs)

CIS192 Python Programming

CIS192 Python Programming

CSE341: Programming Languages Lecture 11 Type Inference. Dan Grossman Spring 2016

Discussion CSE 224. Week 4

STATS Data Analysis using Python. Lecture 8: Hadoop and the mrjob package Some slides adapted from C. Budak

Read & Download (PDF Kindle) Programming Python

Asynchronous I/O: A Case Study in Python


Today. CISC101 Reminders & Notes. Searching in Python - Cont. Searching in Python. From last time

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

PYTHON GUI PROGRAMMING COOKBOOK BY BURKHARD A. MEIER DOWNLOAD EBOOK : PYTHON GUI PROGRAMMING COOKBOOK BY BURKHARD A. MEIER PDF

Welcome to CS50 section! This is Week 10 :(

Easy Graphical User Interfaces

Mid Unit Review. Of the four learning outcomes for this unit, we have covered the first two. 1.1 LO1 2.1 LO2 LO2

CS 4300 Computer Graphics

What Would Python Print? Tuples, Lists, Dictionaries

Lecture 1: Introduction to Python

Strings and Testing string methods, formatting testing approaches CS GMU

Transcription:

CSE 399-004: Python Programming Lecture 08: Graphical User Interfaces with wxpython March 12, 2005 http://www.seas.upenn.edu/~cse39904/

Plan for today and next time Today: wxpython (part 1) Aside: Arguments to functions Whirlwind tour of the widgets Next time: wxpython (part 2) XRCed (?) Event handling Email me by Friday with ideas for something I can build during lecture 2

Arguments to functions (Tutorial 4.7)

Default arguments (Part 1) >>> i = 10 >>> def f(arg = i): print arg >>> i = 20 >>> f() 10 >>> f(15) 15 If no value is supplied for arg, use i. The value of the default argument is evaluated at the point when the function is defined. 4

Default arguments (Part 2) >>> def f(elt, arg = []): arg.append(elt) return arg >>> f(1) [1] >>> f(2) [1, 2] >>> f(3) [1, 2, 3] Arguments with default values must come at the end of the arguments list. If a default value is mutable, its value persists across calls. 5

Keyword arguments (Part 1) >>> def f(foo, bar, baz = 'baz'): print foo, bar, baz >>> f(bar = 2, foo = 3) 3 2 baz >>> f(foo = 1, bar = 2) 1 2 baz >>> f(1, bar = 3) 1 3 baz We can give the values for a functions arguments by name. We can mix positional arguments with keyword arguments, but keyword arguments must come last. 6

Keyword arguments (Part 2) >>> def f(foo, bar = 'bar', baz = 'baz'): print foo, bar, baz >>> f(1) 1 bar baz >>> f(2, baz = 3) 2 bar 3 Using keyword arguments lets us give values to arguments which have default values. 7

General rules for calling functions Positional arguments come before keyword arguments The value of each argument must be given at most once >>> def f(a = 2): print a >>> f() 2 >>> f(10) 10 >>> f(a = 20) 20 8

General rules for calling functions Positional arguments come before keyword arguments The value of each argument must be given at most once >>> def f(a = 2): print a >>> f(a = 30, 0) File "<stdin>", line 1 SyntaxError: non-keyword arg after keyword arg 9

General rules for calling functions Positional arguments come before keyword arguments The value of each argument must be given at most once >>> def f(a = 2): print a >>> f(0, a = 30) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: f() got multiple values for keyword argument ' 10

Arbitrary argument lists >>> def f(arg, bar = 3, *rest, **keywords): print arg, bar, rest, keywords >>> f(1) 1 3 () {} >>> f(1, 2) 1 2 () {} >>> f(1, 2, 3, 4) 1 2 (3, 4) {} >>> f(1, a = 2, b = 3) 1 3 () {'a': 2, 'b': 3} >>> f(1, 2, 3, 4, a = 5, b = 6) 1 2 (3, 4) {'a': 5, 'b': 6} f has one required argument f has two positional arguments 11

Arbitrary argument lists >>> def f(arg, bar = 3, *rest, **keywords): print arg, bar, rest, keywords >>> f(1) 1 3 () {} Extra positional arguments are put >>> f(1, 2) in a tuple and passed in as rest. 1 2 () {} >>> f(1, 2, 3, 4) 1 2 (3, 4) {} >>> f(1, a = 2, b = 3) 1 3 () {'a': 2, 'b': 3} >>> f(1, 2, 3, 4, a = 5, b = 6) 1 2 (3, 4) {'a': 5, 'b': 6} 12

Arbitrary argument lists >>> def f(arg, bar = 3, *rest, **keywords): print arg, bar, rest, keywords >>> f(1) 1 3 () {} >>> f(1, 2) 1 2 () {} >>> f(1, 2, 3, 4) 1 2 (3, 4) {} >>> f(1, a = 2, b = 3) 1 3 () {'a': 2, 'b': 3} >>> f(1, 2, 3, 4, a = 5, b = 6) 1 2 (3, 4) {'a': 5, 'b': 6} Extra keyword arguments are put in a dictionary and passed in as keywords. 13

Arbitrary argument lists >>> def f(arg, bar = 3, *rest, **keywords): print arg, bar, rest, keywords >>> f(1) 1 3 () {} >>> f(1, 2) 1 2 () {} >>> f(1, 2, 3, 4) 1 2 (3, 4) {} >>> f(1, a = 2, b = 3) 1 3 () {'a': 2, 'b': 3} >>> f(1, 2, 3, 4, a = 5, b = 6) 1 2 (3, 4) {'a': 5, 'b': 6} 14

wxpython

wxpython http://www.wxpython.org/ A set of bindings to the cross-platform wxwidgets GUI library (written in C++) Claim: Makes it easy to develop graphical user interfaces (GUIs) for applications in Python 16

Tkinter vs. wxpython Tkinter and wxpython are both GUI libraries for Python Tkinter: Comes with the standard Python distribution Non-native look and feel Cumbersome to build complex UIs "Stale" wxpython: Not part of standard Python distribution Native look and feel Easier to work with than Tkinter "Up and coming" 17

Resources Online API documentation: http://wxpython.wxcommunity.com/docs/api/ Wiki: http://wiki.wxpython.org/index.cgi The demo application that comes with wxpython Has demos of all the widgets Includes the source code for the demos 18

Resources Tutorial: http://wiki.wxpython.org/index.cgi/getting_started Tutorial: http://wiki.wxpython.org/index.cgi/anothertutorial The second is a bit better (in my opinion) Neither does that great a job explaining event handling My suggestion: Work by example 19

Event handling GUIs are event driven: They sit around doing nothing until the user clicks a button, moves the mouse, etc. You, the programmer, are responsible for indicating how events are to be handled You are not responsible for polling for events The style of programming here is quite different from normal sequential programming 20

Some terminology A window is anything that consumes screen space A frame is what you normally think of as a "window" 21