上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Computational Thinking and Approach Lecture 6 Dr.Jialiang LU Jialiang.lu@situ.edu.cn
Computational Thinking and Approach Lecture 6 Dr. Jialiang LU Jialiang.lu@sjtu.edu.cn
上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY GUI OBJECTS AND GRAPHICS
OBJECTS AND GRAPHICS GUI
上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Outlines ·The Object of Objects 。 Simple graphics programming Using Graphical Objects Interactive Graphics ·Displaying Images ·Playing music
Outlines • The Object of Objects • Simple graphics programming • Using Graphical Objects • Interactive Graphics • Displaying Images • Playing music
上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY The Object of Objects The basic idea of object-oriented programming is to view a complex system as the interaction of simpler objects. ·An object consists of -A collection of related information. -A set of operations to manipulate that information. Objects may refer to other objects. Objects interact by sending each other messages (requests for an object to perform one's operations)
The Object of Objects • The basic idea of object-oriented programming is to view a complex system as the interaction of simpler objects. • An object consists of – A collection of related information. – A set of operations to manipulate that information. • Objects may refer to other objects. • Objects interact by sending each other messages (requests for an object to perform one’s operations)
上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Example:time Specification Old style ·Develop a daily time m hours =6 system - m_minutes 30 Morning-call time 6:30:00 -m_seconds =0 Lunch time 12:00:00 I hours 12 Sport time 18:00:00 -I minutes =0 -Iseconds =0 -s hours =18 -s_minutes 0 -s_seconds =0 printTime (hours,minut es,seconds)
Example: time Specification • Develop a daily time system – Morning-call time 6:30:00 – Lunch time 12:00:00 – Sport time 18:00:00 Old style – m_hours = 6 – m_minutes = 30 – m_seconds = 0 – l_hours = 12 – l_minutes = 0 – l_seconds = 0 – s_hours = 18 – s_minutes = 0 – s_seconds = 0 printTime(hours,minut es,seconds)
上降充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Object-Oriented Style Define myTime Create object 。myTime: 。mtime=myTime() hours mtime.hours 6 -minutes mtime.minutes 30 seconds -mtime.seconds 0 ·function ·mtime.printTime() printTime() 。ltime=myTime() ·stime=myTime()
Object-Oriented Style Define myTime • myTime: – hours – minutes – seconds • function – printTime() Create object • mtime = myTime() – mtime.hours = 6 – mtime.minutes = 30 – mtime.seconds = 0 • mtime.printTime() • ltime=myTime() – ... • stime=myTime()
上游充通大学 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY OOP:a good practice of data structure Data structure Data Operation ·OOP Define a type of objects Data associated with the object Operations applicable on the object - Create and use the object through construction and methods
OOP: a good practice of data structure • Data structure – Data – Operation • OOP – Define a type of objects • Data associated with the object • Operations applicable on the object – Create and use the object through construction and methods
上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Simple Graphics Programming Most applications you're familiar with have Graphical User Interfaces (GUl)that provide windows,icons,buttons and menus. 74 Celsius Converter ▣☒ Celsius Temperature: 35 Quit Fahrenheit Temperature: 95.0
Simple Graphics Programming • Most applications you’re familiar with have Graphical User Interfaces (GUI) that provide windows, icons, buttons and menus
上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Simple Graphics Programming Tkinter Python comes with its own standard GUl module called Tkinter. ■graphics.py a simple object oriented graphics library for you Two location choices In Python's Lib directory with other libraries In the same folder as your graphics program
Simple Graphics Programming Tkinter Python comes with its own standard GUI module called Tkinter. graphics.py a simple object oriented graphics library for you Two location choices In Python’s Lib directory with other libraries In the same folder as your graphics program
上游通大¥ ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Graphics.py is an OO Packet over Tkinter Graphics is developed over Tkinter and provide object-oriented library to user. graphics GraphWin Point Rectangle Oval circle Line Text Canvas c.create c.create_ c.create_ c.create rectangle oval line text Tkinter
Graphics.py is an OO Packet over Tkinter • Graphics is developed over Tkinter and provide object-oriented library to user