In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
The knowledge points of this article "how to use tkinter to draw random balls on transparent forms in python" are not quite understood by most people, so the editor summarizes the following contents. The content is detailed, the steps are clear, and it has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article entitled "how to use tkinter to draw random balls on transparent forms in python".
First, draw a big ball and have a look
(1) Core Code
Add the following code to draw a circle inside the on_resize function
Canvas.create_oval (100,100,200,200, outline='yellow', # border color fill='pink', # fill color width=4 # border width) 2. Let the ball move randomly
(1) Core function
Def create_ball (canvas,tk): # tkinter drawing uses screen coordinate system, the origin is in the upper left corner, x increases from left to right, y increases from top to bottom # in the drawing area, the x and y coordinates of the center of the current ball are randomly generated. Used to determine the location of occurrence xpos = randint (10, int (tk.winfo_width () ypos = randint (10, int (tk.winfo_height () # randomly generated to represent the size of the current ball, that is, the radius length radius = randint (40,70) # create a function object r through lambda expression Each call to r () produces the number r = lambda: randint (0,255) # the first two digits of the three calls are stored in self.color in hexadecimal mode, as the color of the ball # RRGGBB, the first 2 is red, the middle 2 is green, the last 2 is blue, and the minimum is 0 The maximum is F # such as all Black # 000000 all White # FFFFFF all Red # FF0000 color = "# xxx"% (r (), r (), r ()) # canvas.create_oval can draw a circle # but you need to pass in the left, upper, right and bottom coordinates of the circle # so we first generate four coordinates, through these four coordinates Draw the size of the circle # left coordinate = x coordinate-radius x1 = xpos-radius # upper coordinate = y coordinate-radius y1 = ypos-radius # right coordinate = x coordinate + radius x2 = xpos + radius # coordinate = y coordinate + radius y2 = ypos + radius # draw the whole circle by canvas.create_oval () method The filler color and the outline color are the colors canvas.delete ('ball') ball = canvas.create_oval generated by self.color (x1, fill=color, outline=color,tag='ball') # canvas.addtag_all (' t5') print (x1, create_ball,canvas,tk) canvas.after (1000, create_ball,canvas,tk) three and more parameters.
(1) remove the title bar
Tk.overrideredirect (1)
(2) display on the top
Tk.wm_attributes ("- topmost", 1)
(3) remove the white edge next to it
Canvas.config (highlightthickness=0) above is about "how to use tkinter in python to draw random balls on transparent forms". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.