COMPSA Exam Prep Session On: April 8th from 1:30-3:00 Location TBA Winter 2016CISC101 - Prof. McLeod1.

Slides:



Advertisements
Similar presentations
Computer Science 112 Fundamentals of Programming II User Interfaces
Advertisements

Tk. Toolkit n Wish - windowing shell –touch fileName –chmod +x fileName –xedit fileName & –#!/usr/local/bin/wish n Widgets - eg Buttons, Labels, Frames.
Tk Widgets This material is best on several sources –Slides by Dr. Ernest J. Friedman-Hill –various Tcl/Tk books.
Noadswood Science,  To know how to use Python to produce windows and colours along with specified co-ordinates Sunday, April 12, 2015.
Intermediate Level Course. Text Format The text styles, bold, italics, underlining, superscript and subscript, can be easily added to selected text. Text.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
COMPSCI 101 Principles of Programming
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Guide to Programming with Python Chapter Ten GUI Development: The Mad Lib Program.
Object Oriented Software Development 9. Creating Graphical User Interfaces.
PC204 Lecture 9 Conrad Huang Genentech Hall, N453A x
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.
Computing Science 1P Lecture 17: Friday 23 rd February Simon Gay Department of Computing Science University of Glasgow 2006/07.
© 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.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
Creating visual interfaces in python
Graphical User Interfaces Tonga Institute of Higher Education.
Winter 2006CISC121 - Prof. McLeod1 Stuff No stuff today!
Guide to Programming with Python
Spring 2006CISC101 - Prof. McLeod1 Last Time The File class. Back to methods –Passing parameters by value and by reference. –Review class attributes. –An.
Today… The for loop. Introducing the Turtle! Loops and Drawing. Winter 2016CISC101 - Prof. McLeod1.
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.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Assignment 5 is posted. Exercise 8 is very similar to what you will be doing with assignment 5. Exam.
Today… Loops and Drawing, Cont. –Two slightly more advanced demos. Collections Overview. Winter 2016CISC101 - Prof. McLeod1.
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
Development Environment
Tk Widgets in Javascript
Topics Graphical User Interfaces Using the tkinter Module
Event Loops and GUI Intro2CS – weeks
Learning to Program D is for Digital.
Graphical User Interfaces (GUIs)
Chapter Topics 15.1 Graphical User Interfaces
3.01 Apply Controls Associated With Visual Studio Form
3.01 Apply Controls Associated With Visual Studio Form
CISC101 Reminders Last lecture!  Grading of Quiz 4 underway.
Chap 7. Building Java Graphical User Interfaces
CISC101 Reminders Grading of Quiz 4 underway.
GUI Using Python.
Graphical User Interfaces -- Introduction
Fundamentals of Python: From First Programs Through Data Structures
This Week: Tkinter for GUI Interfaces Some examples
Tkinter GUIs Computer Science and Software Engineering
CISC101 Reminders Quiz 2 this week.
Winter 2018 CISC101 11/19/2018 CISC101 Reminders
CISC124 Last Quiz this week. Topics listed in last Tuesday’s lecture.
CISC101 Reminders Slides have changed from those posted last night…
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
Winter 2018 CISC101 12/2/2018 CISC101 Reminders
CISC101 Reminders Assn 3 due tomorrow, 7pm.
CISC124 Assignment 4 on Inheritance due next Friday.
Whatcha doin'? Aims: Begin to create GUI applications. Objectives:
Computer Science 111 Fundamentals of Programming I User Interfaces
Winter 2019 CISC101 2/17/2019 CISC101 Reminders
Topics Graphical User Interfaces Using the tkinter Module
Introduction to HTML.
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
CISC101 Reminders Assignment 2 due this Friday.
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
Python – Tkinter Windows Application
The University of Texas – Pan American
CISC101 Reminders Assignment 3 due today.
Winter 2019 CISC101 5/30/2019 CISC101 Reminders
Graphical User Interface
Tkinter User Input Form
Presentation transcript:

COMPSA Exam Prep Session On: April 8th from 1:30-3:00 Location TBA Winter 2016CISC101 - Prof. McLeod1

The Arts and Science Undergraduate Society's Lost Paws's bi-annual animal de-stressing event "Critters on Campus"- will be happening in the JDUC March 29th, 30th and 31st. This event provides students from all faculties with the opportunity to interact with a dog or a cat prior to exam time as a means of stress relief. Dog Walking Sign Up: Dog/Cat Cuddling Sign Ups: Tuesday Wednesday Thursday Winter 2016CISC101 - Prof. McLeod2 Critters on Campus!

Today… Algorithms, Cont.: –Bubble Sort. –Compare search timings. –Sorting, Cont. Visualize: Insertion Selection Bubble Start GUI with Tkinter. Winter 2016CISC101 - Prof. McLeod3

4 Bubble Sort Is best envisioned as a vertical column of numbers as bubbles. The larger bubbles gradually work their way to the top of the column, with the smaller ones pushed down to the bottom. Pseudocode: Loop through list from i=0 to the end: –Loop down from the last element in the list to i. -Swap adjacent elements if they are in the wrong order. Winter 2016

CISC101 - Prof. McLeod5 Bubble Sort, Cont. def bubbleSort(numsList): size = len(numsList) for i in range(0, size): j = size - 1 while j > i : if numsList[j] < numsList[j - 1]: swap(numsList, j, j - 1) j = j - 1 Winter 2016

CISC101 - Prof. McLeod

CISC101 - Prof. McLeod7 Bubble Sort, Cont. Note that both the comparison and the swap are inside the inner loop (yuk!). Winter 2016

CISC101 - Prof. McLeod8 Bubble Sort – A Slight Improvement def bitBetterBubbleSort(numsList): size = len(numsList) i = 0 isSorted = False while i < size and not isSorted: j = size - 1 isSorted = True while j > i : if numsList[j] < numsList[j - 1]: swap(numsList, j, j - 1) isSorted = False j = j - 1 i = i + 1 Winter 2016

CISC101 - Prof. McLeod9 Bubble Sort, Cont. Possibly the simplest sorting algorithm to code. Also the slowest sorting algorithm! On average, bubble sort makes n (the size of the dataset) times more moves than selection or insertion sort. Winter 2016

CISC101 - Prof. McLeod10 Sorting Animations For a collection of animation links see: Here are a few that are OK: ort.html And youtube has videos of many other animations. Winter 2016

CISC101 - Prof. McLeod11 Demo Program See ModifiedSortingTestBed.py How do our sorts compare to list.sort()? (Not very well. How is.sort() so fast?) Winter 2016

CISC101 - Prof. McLeod12 Timings, Summary For 1000 data points between 1 and 1000, random order case. SortMillisec Python sort()0.36 Insertion100 Selection125 Bubble287 Better?Bubble279 Winter 2016

Observations Insertion sort works remarkably well on data that is almost in order. Selection sort doesn’t care much about the state of the data. Bubble sort is always the worst sort, but it behaves slightly better when the data is more ordered. Winter 2016CISC101 - Prof. McLeod13

You are Not Responsible for These Experiments! If I double the size of the list to be sorted do the timings double? Is there a practical limit to the size of the list that can be sorted with our simple sorts? In other words, when do I switch to Quicksort? Binsort is remarkably fast! Why? What is the big restriction on using this sort? Winter 2016CISC101 - Prof. McLeod14

GUI Development in Python “Graphical User Interfaces”! We’ll stick with a distributed module called tkinter. It is easy to learn and use and we know it will work with out current version of Python. But there are many other packages and tookits! CISC101 - Prof. McLeod15Winter 2016

CISC101 - Prof. McLeod16 GUI with Tkinter Stands for “Tk Interface”. It is a Python interface to the Tk GUI toolkit, which is maintained by ActiveState ( they also distribute a free Python development tool called ActivePython, which is an alternative to IDLE). Tk consists of a bunch of components (called “widgets”) developed in C++, which can be used with other languages like Perl or Ruby. See section 25.1 in the Python Library Reference. Winter 2016

CISC101 - Prof. McLeod17 Some Tkinter Widgets Button – something to click on! Canvas – to draw on or display graphics. Checkbutton – a checkbox – on or off. Entry – single line text entry. Frame – container for other widgets. Label – displays one line of text that the user cannot change. Listbox – drop down list for user selection. Menu – a list of choices displayed by a: Menubutton Winter 2016

CISC101 - Prof. McLeod18 Some Tkinter Widgets, Cont. Message – shows multiple lines of text. Radiobutton – appear in groups where the user can only select one. Scale – a slider. Scrollbar – allows scrolling for other widgets. Text – user can enter multiple lines of text. Winter 2016

CISC101 - Prof. McLeod19 Using the tkinter Module One note: IDLE is programmed itself using tkinter and this might cause some strange results. This does not seem to be a problem with Python 3.#, so far… First you must import the tkinter module: import tkinter Or: from tkinter import * If this does not work, then you may have to install the module – but, for Windows Python installs, it should already be there. Winter 2016

CISC101 - Prof. McLeod20 Using tkinter, Cont. Create your main window (or “root” window) using: top_window = tkinter.Tk() Then start the main loop using: tkinter.mainloop() (This assumes you used the first import statement.) Winter 2016

CISC101 - Prof. McLeod21 Using tkinter, Cont. The first line: top_window = tkinter.Tk() invokes the constructor method for the Tk object and now top_window is an object of this type. The main loop is the main “listener” loop for the window – it will wait very patiently for the user to do something! See Window1.py. Note functionality built into even this simple window! Winter 2016

CISC101 - Prof. McLeod22 Add a Label See Window2.py: helloWorldLabel = tkinter.Label(top, text="HelloWorld!") helloWorldLabel.pack() The pack() is invoked to place the label into the first available position in the window. Pretty small font – see Window3.py How can we get away from this top-down stacking of widgets in the window? Winter 2016

CISC101 - Prof. McLeod23 Using Frames See Window4.py Create a Frame, add labels to the Frame, pack the labels and specify a relative position in the Frame, then pack the Frame. Winter 2016

So Far… Can change the window title. Add labels. Use frames. But, using the packer makes for some pretty ugly designs!! CISC101 - Prof. McLeod24Winter 2016

CISC101 - Prof. McLeod25 The Grid Manager The “packer” is very simple but just jams stuff in from top to bottom. You must use frames to get more than one widget in a row. The Grid manager is an alternative that is just a bit harder to use. You specify a row and column position instead. Do not mix the packer and grid together – use one or the other! Winter 2016

CISC101 - Prof. McLeod26 The Grid Manager, Cont. Grid method syntax: grid(row=?, column=?, rowspan=?, columnspan=?, sticky="news", ipadx=?, ipady=?, padx=?, pady=?) "news" is North, East, West, and/or South. row, column positions and rowspan, columnspan are ints. Other “pad” dimensions are in pixels. What is a pixel, anyways? Winter 2016

CISC101 - Prof. McLeod27 The Grid Manager, Cont. See Window5.py Note how the columns and rows are sized to the width and height of the largest widget in that row or column. Widgets are centre-aligned by default – change this using the sticky option. They can span multiple rows and columns – use rowspan or columnspan (or both!). Add extra “padding” using padx and pady. Winter 2016