Computer Science 111 Fundamentals of Programming I Text Areas

Slides:



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

Noadswood Science,  To know how to use Python to produce windows and colours along with specified co-ordinates Sunday, April 12, 2015.
Computer Science 111 Fundamentals of Programming I More Digital Image Processing.
Intermediate Level Course. Text Format The text styles, bold, italics, underlining, superscript and subscript, can be easily added to selected text. Text.
Lesson 6. Links in HTML Computer Science Welcome to Virtual University in Pakistanhttp://
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Computer Science 111 Fundamentals of Programming I User Interfaces Introduction to GUI programming.
Tutorial #9 – Creating Forms. Tutorial #8 Review – Tables Borders (table, gridlines), Border-collapse: collapse; empty-cells: show; and rowspan, colspan.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Tip Calculator App Building an Android App with Java © by Pearson Education, Inc. All Rights Reserved.
Creating a Web Site to Gather Data and Conduct Research.
Guide to Programming with Python Chapter Ten GUI Development: The Mad Lib Program.
Lecture # 6 Forms, Widgets and Event Handling. Today Questions: From notes/reading/life? Share Personal Web Page (if not too personal) 1.Introduce: How.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
Computer Science 112 Fundamentals of Programming II Graphics Programming.
Computer Science 111 Fundamentals of Programming I Model/View/Controller and Data model design.
Dreamweaver MX. 2 Overview of Templates n Forms enable you to collect data from ______. n A form contains ________ such as text fields, radio buttons,
Chapter 5 Quick Links Slide 2 Performance Objectives Understanding Framesets and Frames Creating Framesets and Frames Selecting Framesets and Frames Using.
Computer Science 112 Fundamentals of Programming II Command Buttons and Responding to Events.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 20 Graphical User Interface (GUI)
HTML Form Widgets. Review: HTML Forms HTML forms are used to create web pages that accept user input Forms allow the user to communicate information back.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 9 GUI Programming Using Tkinter 1.
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
GUI development with Matlab: GUI Front Panel Components GUI development with Matlab: Other GUI Components 1 Other GUI components In this section, we will.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
Guide to Programming with Python
Working with the Window Object JavaScript considers the browser window an object, which it calls the window object.
1 /25 Working with Return Templates with TaxWise Online © 2006, Universal Tax Systems, Inc. All Rights Reserved. TaxWise Online Return Templates Objectives.
COMPSA Exam Prep Session by Paul Allison On: April 8th from 1:30-3:00 Location TBA Winter 2016CISC101 - Prof. McLeod1.
1 R3 R1 R5 R4 R6 R2 B B A A Looking at the Code Under the View menu Select Source.
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
This screen may be skipped altogether if the user chooses a report from the server and clicks Ad Hoc or Edit or whatever. Also, the next screen would ordinarily.
Computer Science 112 Fundamentals of Programming II Data Fields for I/O and Message Boxes for Error Recovery.
Chapter 14 The HTML Tag
Multimedia Summer Camp
Fundamentals of Programming I Overview of Programming
CHAPTER 10 JAVA SCRIPT.
Topics Graphical User Interfaces Using the tkinter Module
GUI Final Project: MPEG Maker
Creating LOVs and Editors
Chapter 1: An Introduction to Visual Basic 2015
Computer Science 111 Fundamentals of Programming I
© 2016, Mike Murach & Associates, Inc.
Section 64 – Manipulating Data Using Methods – Java Swing
Using Procedures and Exception Handling
Computer Science 112 Fundamentals of Programming II GUIs II:
Chap 7. Building Java Graphical User Interfaces
CISC101 Reminders Grading of Quiz 4 underway.
Fundamentals of Python: From First Programs Through Data Structures
HTML Forms and User Input
Creating a Workbook Part 2
Objectives Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event.
Tkinter GUIs Computer Science and Software Engineering
Chapter 7 - JavaScript: Introduction to Scripting
Fundamentals of Python: First Programs Second Edition
AWT Components and Containers
JavaScript: Introduction to Scripting
Tutorial 6 Creating Dynamic Pages
Development The Foundation Window.
I210 review.
Fundamentals of Programming I Windows, Labels, and Command Buttons
Computer Science 111 Fundamentals of Programming I User Interfaces
Topics Graphical User Interfaces Using the tkinter Module
Computer Science 111 Fundamentals of Programming I
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
4.4 – List vs Array Exercise 4.1: Array Variables
Chapter 7 - JavaScript: Introduction to Scripting
Presentation transcript:

Computer Science 111 Fundamentals of Programming I Text Areas Radio Buttons and Check Buttons Prompter Boxes Working with Colors

class TaxCode(EasyFrame): """Application window for the tax calculator.""" RATE = .15 EXEMPTION_AMOUNT = 3500.0 def __init__(self): """Sets up the window and the widgets.""" EasyFrame.__init__(self, title = "Tax Calculator") . . . # The event handling method for the button def computeTax(self): """Obtains the data from the input fields and uses them to compute the tax, which is sent to the output field.""" income = self.incomeField.getNumber() exemptions = self.exField.getNumber() tax = max(0.0, (income - exemptions * TaxCode.EXEMPTION_AMOUNT) \ * TaxCode.RATE) self.taxField.setNumber(tax)

Widgets for Text I/O A text field (class TextField) is used for the I/O of one-line strings A text area (class TextArea) is used for the I/O of multiple lines of text See the breezypythongui site for details

Example: A Simple Text File Editor Shows a text area to view and edit the contents of a text file Includes command buttons for opening and saving a file

App Window at Startup

Pop up an Open File Dialog

Load File Contents into Text Area

from breezypythongui import EasyFrame import tkinter.filedialog class FileDialogDemo(EasyFrame): """Demonstrates file dialogs and a text area.""" def __init__(self): """Sets up the window and widgets.""" EasyFrame.__init__(self, "File Dialog Demo") self.outputArea = self.addTextArea("", row = 0, column = 0, columnspan = 2, width = 80, height = 15) self.addButton(text = "Open", row = 1, column = 0, command = self.openFile) self.addButton(text = "Save As...", row = 1, column = 1, command = self.saveFileAs)

from breezypythongui import EasyFrame import tkinter.filedialog class FileDialogDemo(EasyFrame): """Demonstrates file dialogs and a text area.""" . . . # Event handling methods def openFile(self): """Pops up an open file dialog, and if a file is selected, displays its text in the text area.""" filetypes = [("Python files", "*.py"), ("Text files", "*.txt")] fileName = tkinter.filedialog.askopenfilename(parent = self, filetypes = filetypes) if fileName != "": file = open(fileName, "r") text = file.read() file.close() self.outputArea.setText(text) self.setTitle(fileName) def saveFileAs(self): """Pops up a save file dialog, and if a file is selected, saves the contents of the text area to the file.""" fileName = tkinter.filedialog.asksaveasfilename(parent = self) text = self.outputArea.getText() file = open(fileName, "w") file.write(text)

Radio Buttons Might have different tax rates depending on marital status: Single – 20% Married – 15% Divorced – 10%

Radio Buttons Might have different tax rates depending on marital status: Single – 20% Married – 15% Divorced – 10%

Radio Buttons Radio buttons belong to a group Only one radio button in a group can be selected at any given time Add a radio button group to a window or panel first, and then add radio buttons to the group

Adding a Radio Button Group The class EasyRadiobuttonGroup is a subclass of tkinter.Frame The method addRadiobuttonGroup allows spanning over rows and columns in the enclosing container’s grid, as well as an orientation (tkinter.VERTICAL or tkinter.HORIZONTAL) def addRadiobuttonGroup(self, row, column, rowspan = 1, columnspan = 1, orient = VERTICAL):

Adding a Radio Button The class EasyRadiobuttonGroup is a subclass of tkinter.Frame The method addRadiobutton requires a text argument and allows a command function whose default does nothing def addRadiobutton(self, text, command = lambda : 0):

Adding a Radio Button # Radio buttons for filing status self.statusGroup = self.addRadiobuttonGroup(row = 0, column = 2, rowspan = 4) self.single = self.statusGroup.addRadiobutton(text = "Single") self.married = self.statusGroup.addRadiobutton(text = "Married") self.divorced = self.statusGroup.addRadiobutton(text = "Divorced") self.statusGroup["background"] = "pink" self.single["background"] = "pink" self.married["background"] = "pink" self.divorced["background"] = "pink" self.statusGroup.setSelectedButton(self.single)

Accessing a Radio Button # The event handler method for the button def computeTax(self): """Obtains the data from the input field and uses them to compute the tax, which is sent to the output field.""" rate = 0 status = self.statusGroup.getSelectedButton() if status == self.single: rate = .20 elif status == self.married: rate = .15 elif status == self.divorced: rate = .10 income = self.incomeField.getNumber() numDependents = self.depField.getNumber() exemptionAmount = 3000.0 tax = (income - numDependents * exemptionAmount) * rate self.taxField.setNumber(max(tax, 0))

The value Attribute # The event handler method for the button def computeTax(self): """Obtains the data from the input field and uses them to compute the tax, which is sent to the output field.""" rate = 0 status = self.statusGroup.getSelectedButton()["value"] if status == "Single": rate = .20 elif status == "Married": rate = .15 elif status == "Divorced": rate = .10 income = self.incomeField.getNumber() numDependents = self.depField.getNumber() exemptionAmount = 3000.0 tax = (income - numDependents * exemptionAmount) * rate self.taxField.setNumber(max(tax, 0))

Check Buttons Multiple check buttons may be selected at the same time

Check Buttons # The event handler method for the button def __init__(self): """Sets up the window and widgets.""" EasyFrame.__init__(self, "Check Button Demo", background = "lightblue") self.chickCB = self.addCheckbutton(text = "Chicken", row = 0, column = 0) self.taterCB = self.addCheckbutton(text = "French fries", row = 0, column = 1) self.beanCB = self.addCheckbutton(text = "Green beans", row = 1, column = 0) self.sauceCB = self.addCheckbutton(text = "Applesauce", row = 1, column = 1)

Check Buttons def placeOrder(self): """Display a message box with the order information.""" message = "" if self.chickCB.isChecked(): message += "Chicken\n\n" if self.taterCB.isChecked(): message += "French fries\n\n" if self.beanCB.isChecked(): message += "Green beans\n\n" if self.sauceCB.isChecked(): message += "Applesauce\n" if message == "": message = "No food ordered!" self.messageBox(title = "Customer Order", message = message)

Prompter Boxes Pops up a dialog for text input; returns the text entered.

Prompter Boxes Pops up a dialog for text input; returns the text entered.

Prompter Boxes def getUserName(self): """Prompt user for name and display the input in the main window.""" text = self.prompterBox(title = "Input Dialog", promptString = "Your username:") self.label["text"] = "Hi, " + text + "!"

Working with Colors

Working with Colors

Use the colorchooser Module import tkinter.colorchooser . # Event handling method def chooseColor(self): """Pops up a color chooser and outputs the results.""" colorTuple = tkinter.colorchooser.askcolor() if not colorTuple[0]: return ((r, g, b), hexString) = colorTuple self.r.setNumber(int(r)) self.g.setNumber(int(g)) self.b.setNumber(int(b)) self.hex.setText(hexString) self.canvas["background"] = hexString askcolor returns the value (None, None) if the user cancels the color chooser dialog

What Is a Hex String? A hex string represents a color as a six-digit hexadecimal number, with the form “#RRGGBB”

Programmer-Defined Classes Chapter 9 For Friday Programmer-Defined Classes Chapter 9