I would like to know if there is any team that will put the picture in the foreground, set its transparency and block it, that is, the picture will look like a background for a text editor.
- oneeffbot.org/tkinterbook/text.htm - Gleb
- Thanks for the tip, but how to do it with PIL - A.Kross
- I understand you correctly, do you want to set the background for the window? - Gleb
- I want to create a background for the text widget - A.Kross
- Then I hurry to upset you that you cannot create a background for a text widget, if I'm not mistaken, you can't. - Gleb
|
1 answer
I really did not understand what exactly needs to be done, but I can show how to make a picture on the background
from tkinter import * root=Tk()#ΠΌΠΎΠΆΠ½ΠΎ Π²ΠΌΠ΅ΡΡΠΎ root Π½Π°ΠΏΠΈΡΠ°ΡΡ Π»ΡΠ±ΠΎΠ΅ Π½Π°Π·Π²Π°Π½ΠΈΠ΅ ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½ΠΎΠΉ Ρ ΠΎΠΊΠ½ΠΎΠΌ root.state('zoomed')#ΡΡΠΎ Π΄Π΅Π»Π°Π΅Ρ ΠΏΠΎΠ»Π½ΠΎ ΡΠΊΡΠ°Π½Π½ΡΠΉ ΡΠ΅ΠΆΠΈΠΌ ΠΎΠΊΠ½Π° cnv=Canvas(root, width=500, height=500)# Π²ΠΌΠ΅ΡΡΠΎ root, Π²ΠΏΠΈΡΡΠ²Π°Π΅ΠΌ Π½Π°Π·Π²Π°Π½ΠΈΠ΅ ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½ΠΎΠΉ ΡΠΎΠ΄ΠΈΡΠ΅Π»ΡΡΠΊΠΎΠ³ΠΎ ΠΎΠΊΠ½Π° ΠΈ Π² ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½ΡΡ width Π²ΠΏΠΈΡΡΠ²Π°Π΅ΠΌ Π»ΡΠ±ΡΡ ΡΠΈΡΠΈΠ½Ρ Π΄Π»Ρ Π²ΠΈΠ΄ΠΆΠ΅ΡΠ° Canvas ΠΈ Π² ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½ΡΡ height- Π΅Π³ΠΎ Π²ΡΡΠΎΡΡ cnv.pack()# ΡΠ°ΠΏΠΊΠΎΠ²ΡΠ΅ΠΌ Canvas Π² ΡΠΎΠ΄ΠΈΡΠ΅Π»ΡΡΠΊΠΎΠ΅ ΠΎΠΊΠ½ΠΎ Π² ΡΠΊΠΎΠ±ΠΊΠ°Ρ
ΡΠΊΠ°Π·ΡΠ²Π°Π΅ΠΌ Π½ΡΠΆΠ½ΡΠ΅ Π½Π°ΡΡΡΠΎΠΉΠΊΠΈ img=PhotoImage(file='ΠΏΡΡΡ ΠΊ ΠΊΠ°ΡΡΠΈΠ½ΠΊΠ΅')# ΠΌΠΎΠΆΠ½ΠΎ Π»ΡΠ±ΠΎΠ΅ Π΄ΡΡΠ³ΠΎΠ΅ Π½Π°Π·Π²Π°Π½ΠΈΠ΅, ΠΊΡΠΎΠΌΠ΅ img cnv.create_image(image=img, x=5, y=5) #ΡΠΎΠ·Π΄Π°Π΅Ρ ΠΊΠ°ΡΡΠΈΠ½ΠΊΡ x-ΠΏΠΈΠΊΡΠ΅Π»ΠΈ Π² ΡΠΈΡΠΈΠ½Ρ y- ΠΏΠΈΠΊΡΠ΅Π»ΠΈ Π² Π΄Π»ΠΈΠ½Ρ In my opinion, everything is clear and correct. If not, then okay, Iβm just too lazy to check, you can make a Frame and push a picture in there, and on top of it is a Text
- In the future, if you write the code, you need to retreat four spaces or press K + Ctrl. Please read the help first before answering - A.Kross
|