This article example shares the second part of the code of python interactive graphic programming for your reference, as follows
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Draw a smiley face from graphics import * win = GraphWin() face = Circle(Point(100,95), 50) leftEye = Circle(Point(80,80) , 5) ("yellow") ("red") rightEye = Circle(Point(120, 80), 5) ("yellow") ("red") mouth = Line(Point(80, 110), Point(120,110)) (win) (win) (win) (win) ()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Mouse click, return its coordinate value from graphics import * def main(): win = GraphWin("Click Me!") for i in range(10): p = () print("The location you clicked on:", (), ()) if __name__ == '__main__': main()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Mouse click, return its coordinate value from graphics import * win = GraphWin("Draw a polygon.", 300,300) (0.0,0.0,300.0,300.0) message = Text(Point(150, 20),"Five clicks.") (win) # Get the 5 points of the polygon p1 = () (win) p2 = () (win) p3 = () (win) p4 = () (win) p5 = () (win) # Drawing polygons with Polygon objects polygon = Polygon(p1,p2,p3,p4,p5) ("black") ("red") (win) # Wait for response to mouse event, exit program ("Click anywhere to exit.") ()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Draw geometric shapes import turtle def main(): (3) () (-200,-50) () turtle.begin_fill() ("red") (40, steps=3) turtle.end_fill() () (-100,-50) () turtle.begin_fill() ("blue") (40, steps=4) turtle.end_fill() () (0,-50) () turtle.begin_fill() ("green") (40, steps=5) turtle.end_fill() () (100,-50) () turtle.begin_fill() ("yellow") (40, steps=6) turtle.end_fill() () (200,-50) () turtle.begin_fill() ("purple") (40) turtle.end_fill() ("green") () (-100,50) () (("Cool Colorful shapes"), font = ("Times", 18, "bold")) () () if __name__ == '__main__': main()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Simulate chat box from tkinter import * import time def main(): def sendMsg():#Send a message strMsg = 'Me:' + ("%Y-%m-%d %H:%M:%S", ()) + '\n ' (END, strMsg, 'greencolor') (END, ('0.0', END)) ('0.0', END) def cancelMsg():#Cancel message ('0.0', END) def sendMsgEvent(event): #Send Message Event if == "Up": sendMsg() #Creating windows t = Tk() ('In chat with python') #Creating a frame container frmLT = Frame(width=500, height=320, bg='white') frmLC = Frame(width=500, height=150, bg='white') frmLB = Frame(width=500, height=30) frmRT = Frame(width=200, height=500) #Creating Controls txtMsgList = Text(frmLT) txtMsgList.tag_config('greencolor', foreground='#008C00')#create tag txtMsg = Text(frmLC); ("<KeyPress-Up>", sendMsgEvent) btnSend = Button(frmLB, text='Send', width = 8, command=sendMsg) btnCancel = Button(frmLB, text='Cancel', width = 8, command=cancelMsg) imgInfo = PhotoImage(file = "") lblImage = Label(frmRT, image = imgInfo) = imgInfo #Window Layout (row=0, column=0, columnspan=2, padx=1, pady=3) (row=1, column=0, columnspan=2, padx=1, pady=3) (row=2, column=0, columnspan=2) (row=0, column=2, rowspan=3, padx=2, pady=3) #Fixed size frmLT.grid_propagate(0) frmLC.grid_propagate(0) frmLB.grid_propagate(0) frmRT.grid_propagate(0) (row=2, column=0) (row=2, column=1) () () () # Main event loop () if __name__ == '__main__': main()
This is the entire content of this article.