L
L
lnnaannl2021-10-16 22:02:43
Python
lnnaannl, 2021-10-16 22:02:43

The problem is adding a background, how to solve?

There is such an application code

from tkinter import *
import telegram_send

#stiles

root = Tk()

root.title('Kontra')
root.wm_attributes('-alpha', 1.0)
root.geometry('700x450')
root.resizable(width=False, height=False)

     
img = PhotoImage(file='C:/Users/1096419/Desktop/scam_C/ks2.png')      





#to-text


user_text = Entry( root, font = 'Consolas', relief = 'solid', bg = 'silver', width = 50)
user_text.place(x = 135, y = 158) 

#command

def conn():
 
   sv = user_text.get()
   
   telegram_send.send( messages = [ sv ])

   root.destroy()

#style

lbl = Label( text="Введити игровую ссылку", bg="#000000")

btn = Button( text = 'Ввойти', command = conn, height = 2, width = 12,  font=("Consolas", 10, "bold") )
btn.place(x=30, y=50)



user_text = Entry( root, font = 'Consolas', relief = 'solid', bg = 'silver', width = 50)
user_text.place(x = 135, y = 58)

btn = Button( text = 'Рефреш', height = 2, width = 12,  font=("Consolas", 10, "bold") )
btn.place(x=30, y=150)


root.mainloop()


I tried to add a background but an error occurs, you can add the code in the plan to remove the error

Error

Traceback (most recent call last):
  File "main.py", line 14, in <module>
    img = PhotoImage(file='C:/Users/1096419/Desktop/scam_C/ks2.png')
  File "C:\Users\1096419\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 4064, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "C:\Users\1096419\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 4009, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "C:/Users/1096419/Desktop/scam_C/ks2.png"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-10-16
@NeiroNx

Well, firstly, the error is that the image format was not recognized. And secondly, you need to display an image on the Label.

from tkiter import *
root = Tk()
img = PhotoImage(file="D:\\1.png")
l = Label(image=img)
l.place(x=0,y=0)
#остальной код с полями ввода и кнопками

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question