Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement transparent form with python

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to achieve transparent forms in python". In daily operation, I believe many people have doubts about how to achieve transparent forms in python. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "how to achieve transparent forms in python". Next, please follow the editor to study!

I. talking about the basics

(1) implement the simplest form from tkinter import * if _ _ name__ ='_ _ main__': tk = Tk () tk.geometry ('500x400' 500 '150') tk.title ('interesting transparent form-here we go!') Canvas = Canvas (tk) canvas.pack (fill=BOTH, expand=Y) tk.mainloop () 2. The fun begins.

Perhaps the most interesting transparent form starts with such simple code.

We can set a color called transparent color, and then let the form canvas draw a rectangular box, and then set the inner color of the rectangular box to transparent color, then the form will not be transparent?

Oh, isn't it too easy?

Then let's start setting it up.

(1) set gray to transparent color TRANSCOLOUR = 'gray'tk.wm_attributes ('-transparentcolor', TRANSCOLOUR) (2) place a rectangular box on the canvas. Canvas.create_rectangle (0,0, canvas.winfo_width (), canvas.winfo_height (), fill=TRANSCOLOUR, outline=TRANSCOLOUR) (3) have you found any changes? From tkinter import * if _ _ name__ ='_ _ main__': TRANSCOLOUR = 'gray' tk = Tk () tk.geometry (' 500x400 '500' 150') tk.title ('interesting transparent form-here we go!') Canvas = Canvas (tk) canvas.pack (fill=BOTH, expand=Y) canvas.create_rectangle (0,0, canvas.winfo_width (), canvas.winfo_height (), fill=TRANSCOLOUR, outline=TRANSCOLOUR) tk.mainloop ()

Found that the program does not care about my code at all, it is still the same.

But there is no error in the logic and no error in the code, so what's wrong with it?

There are always imperfections behind success

After constantly groping, the original idea is right, but the form works very hard, and it will repeatedly call the operation of redrawing the form, that is to say, in the process of automatic redrawing, the program calls the default code to cover the transparent form I set, so the transparent form is gone.

(1) onsize function def on_resize (evt): tk.configure (width=evt.width,height=evt.height) canvas.create_rectangle (0,0, canvas.winfo_width (), canvas.winfo_height (), fill=TRANSCOLOUR, outline=TRANSCOLOUR) print (canvas.winfo_width ()) (II) bind onsize function tk.bind ('', on_resize), and the study on "how python implements transparent forms" ends. I hope I can solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report