SlideShare a Scribd company logo
INTRODUCTION TO TKINTER
• UP TO THIS POINT WE HAVE BEEN CREATING CONSOLE BASED APPLICATIONS.
• NOW WE ARE GOING TO COMBINE THAT KNOWLEDGE WITH THE OBJECTS WE
STUDIED IN APPINVENTOR.
• WE WILL BE USING THE MODULE TKINTER
• THE TKINTER MODULE IS COMPRISED OF NUMEROUS CLASSES TO CREATE GUI
WIDGETS.
• CODE: FROM TKINTER IMPORT *
CREATING A GRAPHICAL ENVIRONMENT
• THERE ARE 2 MAIN COMPONENTS TO A GUI.
• 1. THE WINDOW/CONTAINER
• 2. THE WIDGETS
• LABELS, BUTTONS, TEXT BOXES, RADIO BUTTONS, IMAGES, ETC.
CREATING A WINDOW AND LABEL
• LET’S BEGIN BY CREATING THE WINDOW, WHICH IS NOTHING MORE THAN A
CONTAINER FOR OUR WIDGETS.
• THE EQUIVALENT TO A SCREEN IN APPINVENTOR
• CODE: WINDOWNAME = TK()
• HOWEVER, THIS WINDOW WILL NOT DO MUCH FOR US UNLESS WE PACK IT WITH
SOME CONTENT.
CREATING A LABEL
• A LABEL IS A WIDGET THAT DISPLAYS INFORMATION. JUST LIKE IN APPINVENTOR.
• CODE: LABELNAME = LABEL(WINDOWNAME, OPTIONS,…)
• OPTIONS INCLUDE:
• TEXT, IMAGES, COLORS, FONT, JUSTIFY, ETC…
• EX.
LBLPROMPT = LABEL(WIND, TEXT =“ HEY”, BG = “RED”)
• AFTER YOU CREATE THE LABEL YOU HAVE TO PUT/PACK IT IN THE WINDOW.
• CODE: LABELNAME.PACK()
• NOTE: THERE ARE NUMEROUS OPTIONS TO EXPLORE
THE EVENT LOOP AND PROCESSING EVENTS
• GUI’S ARE EVENT DRIVEN, MEANING THEY RUN WHEN SOME INTERACTION FROM THE
USER OCCURS.
• TO DETERMINE WHEN AN INTERACTION OCCURS YOU HAVE TO CREATE A LISTENER
FOR EVERY PROGRAMMABLE ACTION THERE IS.
• PYTHON MAKES THIS A BIT EASIER BY USING AN EVENT LOOP TO LISTEN FOR ANY
INTERACTION.
• CODE: WINDOWNAME.MAINLOOP()
EXAMPLE
• QUESTION: HOW CAN WE MODIFY THE BELOW PROGRAM TO PROMPT THE USER TO
ENTER A NAME AND THEN DISPLAY A WELCOME MESSAGE.
IMPORT TKINTER
WIND = TK()
LBLNAME = LABEL(WIND, TEXT = “HEY YOU!”, FG = “BLUE”, FONT =(“HELVETICA, 16))
LBLNAME.PACK()
WIND.MAINLOOP()
THE WIDGET CLASSES
• WHEN CREATING A WIDGET THERE ARE
SPECIFIC PARAMETERS FOR EACH TO SPECIFY.
• WHERE TO PLACE IT
• PROPERTIES
• VARIABLES TO SET, ETC.
Widget Class Description
Button A simple button, used to execute a command.
Checkbutton Clicking a check button toggles between the values.
Radiobutton Clicking a radio button sets the variable to that value,
and clears all other radio buttons associated with the
same variable.
Entry A text entry field, a.k.a a text field or a text box.
Frame A container widget for containing other widgets.
Menu A menu pane, used to implement pull down and popup menus.
Menubutton A menu button, used to implement pull down menus.
Label Displays a text or an image.
Message Displays a text. Similar to the label widget, but can
automatically wrap text to a given width or aspect ratio.
Text Formatted text display. Allows you to display and edit
text with various styles and attributes. Also supports
embedded images and windows.
Scale Allows you to set a numerical value by dragging a
"slider".
Canvas Structured graphics, used to draw graphs and plots,
create graphics editors, and to implement custom widgets.
Toplevel A container widget displayed as a separate, top-level
window.
CHANGING PROPERTIES OF WIDGETS
• COLOR AND FONT
• TO SPECIFY A COLOR, YOU CAN EITHER USE A COLOR NAME SUCH AS RED, YELLOW, GREEN, BLUE, WHITE, BLACK, PURPLE, ETC, OR EXPLICITLY SPECIFY THE RED, GREEN, AND BLUE
(RGB) COLOR COMPONENTS USING A STRING #RRGGBB, WHERE RR, GG, BB ARE HEXADECIMAL REPRESENTATIONS OF THE RED, GREEN AND BLUE VALUES, RESPECTIVELY.
• "TIMES 10 BOLD"
• "HELVETICA 10 BOLD ITALIC"
• "COURIER NEW 20 BOLD ITALIC"
• "COURIER NEW 20 BOLD ITALIC OVER STRIKE UNDERLINE"
• TEXT PROPERTIES
• THE TEXT IN A LABEL AND A BUTTON IS CENTERED
BY DEFAULT. YOU CAN CHANGE IT BY USING THE JUSTIFY
OPTION WITH VALUES LEFT, CENTER, OR RIGHT. YOU
CAN ALSO DISPLAY THE TEXT IN MULTIPLE LINES BY
INSERTING THE NEWLINE CHARACTER N TO SEPARATE TEXTS.
• MOUSE CURSOR
• YOU CAN SET A MOUSE CURSOR BY USING THE CURSOR OPTION WITH VALUES SUCH AS "ARROW" (DEFAULT), "CIRCLE", "CROSS" "PLUS", ETC.
• CODE: WIDGETNAME["PROPERTYNAME] = NEWPROPERTYVALUE
EXAMPLE
import tkinter
def btnNameProcess(name):
lblName["text"]= "Hey " + name
wind = tkinter.Tk()
wind.title("GUI Test Program")
wind.minsize(200,200)
lblName = tkinter.Label(wind, text ="Hey You", fg ="blue", bg = "#fff")
enterName = tkinter.StringVar() entName = tkinter.Entry(wind,text = "Me")
btnName = tkinter.Button(wind, text = "Press Me", command = lambda: btnNameProcess(entName.get()))
lblName.pack()
entName.pack()
btnName.pack()
wind.mainloop()

More Related Content

Similar to Introduction to Graphics

CodeStock :: Introduction To MacRuby and HotCocoa
CodeStock :: Introduction To MacRuby and HotCocoaCodeStock :: Introduction To MacRuby and HotCocoa
CodeStock :: Introduction To MacRuby and HotCocoa
Doc Norton
 
Visual Basic IDE Intro.pdf
Visual Basic IDE Intro.pdfVisual Basic IDE Intro.pdf
Visual Basic IDE Intro.pdf
sheenmarie0212
 
Visual Basic IDE Introduction
Visual Basic IDE IntroductionVisual Basic IDE Introduction
Visual Basic IDE Introduction
Ahllen Javier
 
Cassandra and materialized views
Cassandra and materialized viewsCassandra and materialized views
Cassandra and materialized views
Grzegorz Duda
 
Algorithm Design and Problem Solving [Autosaved].pptx
Algorithm Design and Problem Solving [Autosaved].pptxAlgorithm Design and Problem Solving [Autosaved].pptx
Algorithm Design and Problem Solving [Autosaved].pptx
KaavyaGaur1
 
Visual basic
Visual basicVisual basic
Visual basic
KavithaAlagumalai
 
QGIS Tutorial 1
QGIS Tutorial 1QGIS Tutorial 1
QGIS Tutorial 1
niloyghosh1984
 
Visual Basic.pptx
Visual Basic.pptxVisual Basic.pptx
Visual Basic.pptx
KavithaAlagumalai
 
Feature Engineering
Feature EngineeringFeature Engineering
Feature Engineering
HJ van Veen
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll build
Mark Stoodley
 
Unreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User InterfaceUnreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User Interface
Nick Pruehs
 
autocadppt.pptx
autocadppt.pptxautocadppt.pptx
autocadppt.pptx
NannuJoshi
 
microbit Microbit programming Microbit programming
microbit Microbit programming Microbit programmingmicrobit Microbit programming Microbit programming
microbit Microbit programming Microbit programming
ssuser5feb2c1
 
Adobe pagemaker
Adobe pagemakerAdobe pagemaker
Adobe pagemaker
Umamaheshwariv1
 
Digital Calipers Software Mitutoyo / Logiciel pour Pied à coulisse Mitutoyo (...
Digital Calipers Software Mitutoyo / Logiciel pour Pied à coulisse Mitutoyo (...Digital Calipers Software Mitutoyo / Logiciel pour Pied à coulisse Mitutoyo (...
Digital Calipers Software Mitutoyo / Logiciel pour Pied à coulisse Mitutoyo (...topomax
 
Having fun power apps components HandsOn - Power Platform World Tour Copenhag...
Having fun power apps components HandsOn - Power Platform World Tour Copenhag...Having fun power apps components HandsOn - Power Platform World Tour Copenhag...
Having fun power apps components HandsOn - Power Platform World Tour Copenhag...
Rebekka Aalbers-de Jong
 
iBeacons - the new low-powered way of location awareness
iBeacons - the new low-powered way of location awarenessiBeacons - the new low-powered way of location awareness
iBeacons - the new low-powered way of location awarenessStefano Zanetti
 
Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1
Bhushan Mulmule
 
Week 1
Week 1Week 1
Week 1
EasyStudy3
 
Windows mobile programming
Windows mobile programmingWindows mobile programming
Windows mobile programming
Dr. Ramkumar Lakshminarayanan
 

Similar to Introduction to Graphics (20)

CodeStock :: Introduction To MacRuby and HotCocoa
CodeStock :: Introduction To MacRuby and HotCocoaCodeStock :: Introduction To MacRuby and HotCocoa
CodeStock :: Introduction To MacRuby and HotCocoa
 
Visual Basic IDE Intro.pdf
Visual Basic IDE Intro.pdfVisual Basic IDE Intro.pdf
Visual Basic IDE Intro.pdf
 
Visual Basic IDE Introduction
Visual Basic IDE IntroductionVisual Basic IDE Introduction
Visual Basic IDE Introduction
 
Cassandra and materialized views
Cassandra and materialized viewsCassandra and materialized views
Cassandra and materialized views
 
Algorithm Design and Problem Solving [Autosaved].pptx
Algorithm Design and Problem Solving [Autosaved].pptxAlgorithm Design and Problem Solving [Autosaved].pptx
Algorithm Design and Problem Solving [Autosaved].pptx
 
Visual basic
Visual basicVisual basic
Visual basic
 
QGIS Tutorial 1
QGIS Tutorial 1QGIS Tutorial 1
QGIS Tutorial 1
 
Visual Basic.pptx
Visual Basic.pptxVisual Basic.pptx
Visual Basic.pptx
 
Feature Engineering
Feature EngineeringFeature Engineering
Feature Engineering
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll build
 
Unreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User InterfaceUnreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User Interface
 
autocadppt.pptx
autocadppt.pptxautocadppt.pptx
autocadppt.pptx
 
microbit Microbit programming Microbit programming
microbit Microbit programming Microbit programmingmicrobit Microbit programming Microbit programming
microbit Microbit programming Microbit programming
 
Adobe pagemaker
Adobe pagemakerAdobe pagemaker
Adobe pagemaker
 
Digital Calipers Software Mitutoyo / Logiciel pour Pied à coulisse Mitutoyo (...
Digital Calipers Software Mitutoyo / Logiciel pour Pied à coulisse Mitutoyo (...Digital Calipers Software Mitutoyo / Logiciel pour Pied à coulisse Mitutoyo (...
Digital Calipers Software Mitutoyo / Logiciel pour Pied à coulisse Mitutoyo (...
 
Having fun power apps components HandsOn - Power Platform World Tour Copenhag...
Having fun power apps components HandsOn - Power Platform World Tour Copenhag...Having fun power apps components HandsOn - Power Platform World Tour Copenhag...
Having fun power apps components HandsOn - Power Platform World Tour Copenhag...
 
iBeacons - the new low-powered way of location awareness
iBeacons - the new low-powered way of location awarenessiBeacons - the new low-powered way of location awareness
iBeacons - the new low-powered way of location awareness
 
Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1
 
Week 1
Week 1Week 1
Week 1
 
Windows mobile programming
Windows mobile programmingWindows mobile programming
Windows mobile programming
 

More from primeteacher32

Software Development Life Cycle
Software Development Life CycleSoftware Development Life Cycle
Software Development Life Cycle
primeteacher32
 
Variable Scope
Variable ScopeVariable Scope
Variable Scope
primeteacher32
 
Returning Data
Returning DataReturning Data
Returning Data
primeteacher32
 
Intro to Functions
Intro to FunctionsIntro to Functions
Intro to Functions
primeteacher32
 
Introduction to GUIs with guizero
Introduction to GUIs with guizeroIntroduction to GUIs with guizero
Introduction to GUIs with guizero
primeteacher32
 
Function Parameters
Function ParametersFunction Parameters
Function Parameters
primeteacher32
 
Nested Loops
Nested LoopsNested Loops
Nested Loops
primeteacher32
 
Conditional Loops
Conditional LoopsConditional Loops
Conditional Loops
primeteacher32
 
Introduction to Repetition Structures
Introduction to Repetition StructuresIntroduction to Repetition Structures
Introduction to Repetition Structures
primeteacher32
 
Input Validation
Input ValidationInput Validation
Input Validation
primeteacher32
 
Windows File Systems
Windows File SystemsWindows File Systems
Windows File Systems
primeteacher32
 
Nesting Conditionals
Nesting ConditionalsNesting Conditionals
Nesting Conditionals
primeteacher32
 
Conditionals
ConditionalsConditionals
Conditionals
primeteacher32
 
Intro to Python with GPIO
Intro to Python with GPIOIntro to Python with GPIO
Intro to Python with GPIO
primeteacher32
 
Variables and Statements
Variables and StatementsVariables and Statements
Variables and Statements
primeteacher32
 
Variables and User Input
Variables and User InputVariables and User Input
Variables and User Input
primeteacher32
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
primeteacher32
 
Raspberry Pi
Raspberry PiRaspberry Pi
Raspberry Pi
primeteacher32
 
Hardware vs. Software Presentations
Hardware vs. Software PresentationsHardware vs. Software Presentations
Hardware vs. Software Presentations
primeteacher32
 
Block chain security
Block chain securityBlock chain security
Block chain security
primeteacher32
 

More from primeteacher32 (20)

Software Development Life Cycle
Software Development Life CycleSoftware Development Life Cycle
Software Development Life Cycle
 
Variable Scope
Variable ScopeVariable Scope
Variable Scope
 
Returning Data
Returning DataReturning Data
Returning Data
 
Intro to Functions
Intro to FunctionsIntro to Functions
Intro to Functions
 
Introduction to GUIs with guizero
Introduction to GUIs with guizeroIntroduction to GUIs with guizero
Introduction to GUIs with guizero
 
Function Parameters
Function ParametersFunction Parameters
Function Parameters
 
Nested Loops
Nested LoopsNested Loops
Nested Loops
 
Conditional Loops
Conditional LoopsConditional Loops
Conditional Loops
 
Introduction to Repetition Structures
Introduction to Repetition StructuresIntroduction to Repetition Structures
Introduction to Repetition Structures
 
Input Validation
Input ValidationInput Validation
Input Validation
 
Windows File Systems
Windows File SystemsWindows File Systems
Windows File Systems
 
Nesting Conditionals
Nesting ConditionalsNesting Conditionals
Nesting Conditionals
 
Conditionals
ConditionalsConditionals
Conditionals
 
Intro to Python with GPIO
Intro to Python with GPIOIntro to Python with GPIO
Intro to Python with GPIO
 
Variables and Statements
Variables and StatementsVariables and Statements
Variables and Statements
 
Variables and User Input
Variables and User InputVariables and User Input
Variables and User Input
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Raspberry Pi
Raspberry PiRaspberry Pi
Raspberry Pi
 
Hardware vs. Software Presentations
Hardware vs. Software PresentationsHardware vs. Software Presentations
Hardware vs. Software Presentations
 
Block chain security
Block chain securityBlock chain security
Block chain security
 

Recently uploaded

New Explore Careers and College Majors 2024
New Explore Careers and College Majors 2024New Explore Careers and College Majors 2024
New Explore Careers and College Majors 2024
Dr. Mary Askew
 
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdfDOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
Pushpendra Kumar
 
MISS TEEN GONDA 2024 - WINNER ABHA VISHWAKARMA
MISS TEEN GONDA 2024 - WINNER ABHA VISHWAKARMAMISS TEEN GONDA 2024 - WINNER ABHA VISHWAKARMA
MISS TEEN GONDA 2024 - WINNER ABHA VISHWAKARMA
DK PAGEANT
 
Lbs last rank 2023 9988kr47h4744j445.pdf
Lbs last rank 2023 9988kr47h4744j445.pdfLbs last rank 2023 9988kr47h4744j445.pdf
Lbs last rank 2023 9988kr47h4744j445.pdf
ashiquepa3
 
一比一原版(QU毕业证)皇后大学毕业证如何办理
一比一原版(QU毕业证)皇后大学毕业证如何办理一比一原版(QU毕业证)皇后大学毕业证如何办理
一比一原版(QU毕业证)皇后大学毕业证如何办理
yuhofha
 
一比一原版(U-Barcelona毕业证)巴塞罗那大学毕业证成绩单如何办理
一比一原版(U-Barcelona毕业证)巴塞罗那大学毕业证成绩单如何办理一比一原版(U-Barcelona毕业证)巴塞罗那大学毕业证成绩单如何办理
一比一原版(U-Barcelona毕业证)巴塞罗那大学毕业证成绩单如何办理
taqyed
 
Full Sail_Morales_Michael_SMM_2024-05.pptx
Full Sail_Morales_Michael_SMM_2024-05.pptxFull Sail_Morales_Michael_SMM_2024-05.pptx
Full Sail_Morales_Michael_SMM_2024-05.pptx
mmorales2173
 
Resumes, Cover Letters, and Applying Online
Resumes, Cover Letters, and Applying OnlineResumes, Cover Letters, and Applying Online
Resumes, Cover Letters, and Applying Online
Bruce Bennett
 
在线制作加拿大萨省大学毕业证文凭证书实拍图原版一模一样
在线制作加拿大萨省大学毕业证文凭证书实拍图原版一模一样在线制作加拿大萨省大学毕业证文凭证书实拍图原版一模一样
在线制作加拿大萨省大学毕业证文凭证书实拍图原版一模一样
2zjra9bn
 
一比一原版(YU毕业证)约克大学毕业证如何办理
一比一原版(YU毕业证)约克大学毕业证如何办理一比一原版(YU毕业证)约克大学毕业证如何办理
一比一原版(YU毕业证)约克大学毕业证如何办理
yuhofha
 
Leadership Ambassador club Adventist module
Leadership Ambassador club Adventist moduleLeadership Ambassador club Adventist module
Leadership Ambassador club Adventist module
kakomaeric00
 
Erection Methodology (KG Marg) MLCP.pptx
Erection Methodology (KG Marg) MLCP.pptxErection Methodology (KG Marg) MLCP.pptx
Erection Methodology (KG Marg) MLCP.pptx
zrahman0161
 
RECOGNITION AWARD 13 - TO ALESSANDRO MARTINS.pdf
RECOGNITION AWARD 13 - TO ALESSANDRO MARTINS.pdfRECOGNITION AWARD 13 - TO ALESSANDRO MARTINS.pdf
RECOGNITION AWARD 13 - TO ALESSANDRO MARTINS.pdf
AlessandroMartins454470
 
一比一原版(UVic毕业证)维多利亚大学毕业证如何办理
一比一原版(UVic毕业证)维多利亚大学毕业证如何办理一比一原版(UVic毕业证)维多利亚大学毕业证如何办理
一比一原版(UVic毕业证)维多利亚大学毕业证如何办理
pxyhy
 
Personal Brand exploration KE.pdf for assignment
Personal Brand exploration KE.pdf for assignmentPersonal Brand exploration KE.pdf for assignment
Personal Brand exploration KE.pdf for assignment
ragingokie
 
原版制作(RMIT毕业证书)墨尔本皇家理工大学毕业证在读证明一模一样
原版制作(RMIT毕业证书)墨尔本皇家理工大学毕业证在读证明一模一样原版制作(RMIT毕业证书)墨尔本皇家理工大学毕业证在读证明一模一样
原版制作(RMIT毕业证书)墨尔本皇家理工大学毕业证在读证明一模一样
atwvhyhm
 
lab.123456789123456789123456789123456789
lab.123456789123456789123456789123456789lab.123456789123456789123456789123456789
lab.123456789123456789123456789123456789
Ghh
 
一比一原版(TMU毕业证)多伦多都会大学毕业证如何办理
一比一原版(TMU毕业证)多伦多都会大学毕业证如何办理一比一原版(TMU毕业证)多伦多都会大学毕业证如何办理
一比一原版(TMU毕业证)多伦多都会大学毕业证如何办理
yuhofha
 
Exploring Career Paths in Cybersecurity for Technical Communicators
Exploring Career Paths in Cybersecurity for Technical CommunicatorsExploring Career Paths in Cybersecurity for Technical Communicators
Exploring Career Paths in Cybersecurity for Technical Communicators
Ben Woelk, CISSP, CPTC
 
官方认证美国旧金山州立大学毕业证学位证书案例原版一模一样
官方认证美国旧金山州立大学毕业证学位证书案例原版一模一样官方认证美国旧金山州立大学毕业证学位证书案例原版一模一样
官方认证美国旧金山州立大学毕业证学位证书案例原版一模一样
2zjra9bn
 

Recently uploaded (20)

New Explore Careers and College Majors 2024
New Explore Careers and College Majors 2024New Explore Careers and College Majors 2024
New Explore Careers and College Majors 2024
 
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdfDOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
 
MISS TEEN GONDA 2024 - WINNER ABHA VISHWAKARMA
MISS TEEN GONDA 2024 - WINNER ABHA VISHWAKARMAMISS TEEN GONDA 2024 - WINNER ABHA VISHWAKARMA
MISS TEEN GONDA 2024 - WINNER ABHA VISHWAKARMA
 
Lbs last rank 2023 9988kr47h4744j445.pdf
Lbs last rank 2023 9988kr47h4744j445.pdfLbs last rank 2023 9988kr47h4744j445.pdf
Lbs last rank 2023 9988kr47h4744j445.pdf
 
一比一原版(QU毕业证)皇后大学毕业证如何办理
一比一原版(QU毕业证)皇后大学毕业证如何办理一比一原版(QU毕业证)皇后大学毕业证如何办理
一比一原版(QU毕业证)皇后大学毕业证如何办理
 
一比一原版(U-Barcelona毕业证)巴塞罗那大学毕业证成绩单如何办理
一比一原版(U-Barcelona毕业证)巴塞罗那大学毕业证成绩单如何办理一比一原版(U-Barcelona毕业证)巴塞罗那大学毕业证成绩单如何办理
一比一原版(U-Barcelona毕业证)巴塞罗那大学毕业证成绩单如何办理
 
Full Sail_Morales_Michael_SMM_2024-05.pptx
Full Sail_Morales_Michael_SMM_2024-05.pptxFull Sail_Morales_Michael_SMM_2024-05.pptx
Full Sail_Morales_Michael_SMM_2024-05.pptx
 
Resumes, Cover Letters, and Applying Online
Resumes, Cover Letters, and Applying OnlineResumes, Cover Letters, and Applying Online
Resumes, Cover Letters, and Applying Online
 
在线制作加拿大萨省大学毕业证文凭证书实拍图原版一模一样
在线制作加拿大萨省大学毕业证文凭证书实拍图原版一模一样在线制作加拿大萨省大学毕业证文凭证书实拍图原版一模一样
在线制作加拿大萨省大学毕业证文凭证书实拍图原版一模一样
 
一比一原版(YU毕业证)约克大学毕业证如何办理
一比一原版(YU毕业证)约克大学毕业证如何办理一比一原版(YU毕业证)约克大学毕业证如何办理
一比一原版(YU毕业证)约克大学毕业证如何办理
 
Leadership Ambassador club Adventist module
Leadership Ambassador club Adventist moduleLeadership Ambassador club Adventist module
Leadership Ambassador club Adventist module
 
Erection Methodology (KG Marg) MLCP.pptx
Erection Methodology (KG Marg) MLCP.pptxErection Methodology (KG Marg) MLCP.pptx
Erection Methodology (KG Marg) MLCP.pptx
 
RECOGNITION AWARD 13 - TO ALESSANDRO MARTINS.pdf
RECOGNITION AWARD 13 - TO ALESSANDRO MARTINS.pdfRECOGNITION AWARD 13 - TO ALESSANDRO MARTINS.pdf
RECOGNITION AWARD 13 - TO ALESSANDRO MARTINS.pdf
 
一比一原版(UVic毕业证)维多利亚大学毕业证如何办理
一比一原版(UVic毕业证)维多利亚大学毕业证如何办理一比一原版(UVic毕业证)维多利亚大学毕业证如何办理
一比一原版(UVic毕业证)维多利亚大学毕业证如何办理
 
Personal Brand exploration KE.pdf for assignment
Personal Brand exploration KE.pdf for assignmentPersonal Brand exploration KE.pdf for assignment
Personal Brand exploration KE.pdf for assignment
 
原版制作(RMIT毕业证书)墨尔本皇家理工大学毕业证在读证明一模一样
原版制作(RMIT毕业证书)墨尔本皇家理工大学毕业证在读证明一模一样原版制作(RMIT毕业证书)墨尔本皇家理工大学毕业证在读证明一模一样
原版制作(RMIT毕业证书)墨尔本皇家理工大学毕业证在读证明一模一样
 
lab.123456789123456789123456789123456789
lab.123456789123456789123456789123456789lab.123456789123456789123456789123456789
lab.123456789123456789123456789123456789
 
一比一原版(TMU毕业证)多伦多都会大学毕业证如何办理
一比一原版(TMU毕业证)多伦多都会大学毕业证如何办理一比一原版(TMU毕业证)多伦多都会大学毕业证如何办理
一比一原版(TMU毕业证)多伦多都会大学毕业证如何办理
 
Exploring Career Paths in Cybersecurity for Technical Communicators
Exploring Career Paths in Cybersecurity for Technical CommunicatorsExploring Career Paths in Cybersecurity for Technical Communicators
Exploring Career Paths in Cybersecurity for Technical Communicators
 
官方认证美国旧金山州立大学毕业证学位证书案例原版一模一样
官方认证美国旧金山州立大学毕业证学位证书案例原版一模一样官方认证美国旧金山州立大学毕业证学位证书案例原版一模一样
官方认证美国旧金山州立大学毕业证学位证书案例原版一模一样
 

Introduction to Graphics

  • 1.
  • 2. INTRODUCTION TO TKINTER • UP TO THIS POINT WE HAVE BEEN CREATING CONSOLE BASED APPLICATIONS. • NOW WE ARE GOING TO COMBINE THAT KNOWLEDGE WITH THE OBJECTS WE STUDIED IN APPINVENTOR. • WE WILL BE USING THE MODULE TKINTER • THE TKINTER MODULE IS COMPRISED OF NUMEROUS CLASSES TO CREATE GUI WIDGETS. • CODE: FROM TKINTER IMPORT *
  • 3. CREATING A GRAPHICAL ENVIRONMENT • THERE ARE 2 MAIN COMPONENTS TO A GUI. • 1. THE WINDOW/CONTAINER • 2. THE WIDGETS • LABELS, BUTTONS, TEXT BOXES, RADIO BUTTONS, IMAGES, ETC.
  • 4. CREATING A WINDOW AND LABEL • LET’S BEGIN BY CREATING THE WINDOW, WHICH IS NOTHING MORE THAN A CONTAINER FOR OUR WIDGETS. • THE EQUIVALENT TO A SCREEN IN APPINVENTOR • CODE: WINDOWNAME = TK() • HOWEVER, THIS WINDOW WILL NOT DO MUCH FOR US UNLESS WE PACK IT WITH SOME CONTENT.
  • 5. CREATING A LABEL • A LABEL IS A WIDGET THAT DISPLAYS INFORMATION. JUST LIKE IN APPINVENTOR. • CODE: LABELNAME = LABEL(WINDOWNAME, OPTIONS,…) • OPTIONS INCLUDE: • TEXT, IMAGES, COLORS, FONT, JUSTIFY, ETC… • EX. LBLPROMPT = LABEL(WIND, TEXT =“ HEY”, BG = “RED”) • AFTER YOU CREATE THE LABEL YOU HAVE TO PUT/PACK IT IN THE WINDOW. • CODE: LABELNAME.PACK() • NOTE: THERE ARE NUMEROUS OPTIONS TO EXPLORE
  • 6. THE EVENT LOOP AND PROCESSING EVENTS • GUI’S ARE EVENT DRIVEN, MEANING THEY RUN WHEN SOME INTERACTION FROM THE USER OCCURS. • TO DETERMINE WHEN AN INTERACTION OCCURS YOU HAVE TO CREATE A LISTENER FOR EVERY PROGRAMMABLE ACTION THERE IS. • PYTHON MAKES THIS A BIT EASIER BY USING AN EVENT LOOP TO LISTEN FOR ANY INTERACTION. • CODE: WINDOWNAME.MAINLOOP()
  • 7. EXAMPLE • QUESTION: HOW CAN WE MODIFY THE BELOW PROGRAM TO PROMPT THE USER TO ENTER A NAME AND THEN DISPLAY A WELCOME MESSAGE. IMPORT TKINTER WIND = TK() LBLNAME = LABEL(WIND, TEXT = “HEY YOU!”, FG = “BLUE”, FONT =(“HELVETICA, 16)) LBLNAME.PACK() WIND.MAINLOOP()
  • 8. THE WIDGET CLASSES • WHEN CREATING A WIDGET THERE ARE SPECIFIC PARAMETERS FOR EACH TO SPECIFY. • WHERE TO PLACE IT • PROPERTIES • VARIABLES TO SET, ETC. Widget Class Description Button A simple button, used to execute a command. Checkbutton Clicking a check button toggles between the values. Radiobutton Clicking a radio button sets the variable to that value, and clears all other radio buttons associated with the same variable. Entry A text entry field, a.k.a a text field or a text box. Frame A container widget for containing other widgets. Menu A menu pane, used to implement pull down and popup menus. Menubutton A menu button, used to implement pull down menus. Label Displays a text or an image. Message Displays a text. Similar to the label widget, but can automatically wrap text to a given width or aspect ratio. Text Formatted text display. Allows you to display and edit text with various styles and attributes. Also supports embedded images and windows. Scale Allows you to set a numerical value by dragging a "slider". Canvas Structured graphics, used to draw graphs and plots, create graphics editors, and to implement custom widgets. Toplevel A container widget displayed as a separate, top-level window.
  • 9. CHANGING PROPERTIES OF WIDGETS • COLOR AND FONT • TO SPECIFY A COLOR, YOU CAN EITHER USE A COLOR NAME SUCH AS RED, YELLOW, GREEN, BLUE, WHITE, BLACK, PURPLE, ETC, OR EXPLICITLY SPECIFY THE RED, GREEN, AND BLUE (RGB) COLOR COMPONENTS USING A STRING #RRGGBB, WHERE RR, GG, BB ARE HEXADECIMAL REPRESENTATIONS OF THE RED, GREEN AND BLUE VALUES, RESPECTIVELY. • "TIMES 10 BOLD" • "HELVETICA 10 BOLD ITALIC" • "COURIER NEW 20 BOLD ITALIC" • "COURIER NEW 20 BOLD ITALIC OVER STRIKE UNDERLINE" • TEXT PROPERTIES • THE TEXT IN A LABEL AND A BUTTON IS CENTERED BY DEFAULT. YOU CAN CHANGE IT BY USING THE JUSTIFY OPTION WITH VALUES LEFT, CENTER, OR RIGHT. YOU CAN ALSO DISPLAY THE TEXT IN MULTIPLE LINES BY INSERTING THE NEWLINE CHARACTER N TO SEPARATE TEXTS. • MOUSE CURSOR • YOU CAN SET A MOUSE CURSOR BY USING THE CURSOR OPTION WITH VALUES SUCH AS "ARROW" (DEFAULT), "CIRCLE", "CROSS" "PLUS", ETC. • CODE: WIDGETNAME["PROPERTYNAME] = NEWPROPERTYVALUE
  • 10. EXAMPLE import tkinter def btnNameProcess(name): lblName["text"]= "Hey " + name wind = tkinter.Tk() wind.title("GUI Test Program") wind.minsize(200,200) lblName = tkinter.Label(wind, text ="Hey You", fg ="blue", bg = "#fff") enterName = tkinter.StringVar() entName = tkinter.Entry(wind,text = "Me") btnName = tkinter.Button(wind, text = "Press Me", command = lambda: btnNameProcess(entName.get())) lblName.pack() entName.pack() btnName.pack() wind.mainloop()