Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Python

Tkinter में Images को Backgrounds के रूप में कैसे उपयोग करें?

यदि हम Tkinter frame का instance बनाएंगे और window display करेंगे जबकि इसे चलाते रहेंगे, तो यह default output canvas दिखाएगा। हालांकि, हम PhotoImage methods और Canvas methods का उपयोग करके Tkinter canvas के अंदर एक image को background के रूप में जोड़ सकते हैं।

चूंकि Tkinter में image support GIF, PNG और PPM तक सीमित है, PhotoImage(GIF, PNG, PPM) फंक्शन image file का location लेता है और image को background के रूप में canvas display करता है।

पहले, हम PhotoImage function का उपयोग करके एक PhotoImage Object बनाएंगे।

उदाहरण

from tkinter import *
from PIL import ImageTk

win = Tk()
win.geometry("700x300")

# Define the PhotoImage Constructor by passing the image file
img = PhotoImage(file='down.png', master=win)
img_label = Label(win, image=img)

# Define the position of the image
img_label.place(x=0, y=0)

win.mainloop()

आउटपुट

उपरोक्त code snippet चलाने से background image के साथ एक window display होगी।

Tkinter में Images को Backgrounds के रूप में कैसे उपयोग करें?

  1. Tkinter में Image को Button के रूप में कैसे उपयोग करें? Tkinter में Image को Button के रूप में कैसे उपयोग करें?

    इस उदाहरण में, हम एक window में rounded button बनाएंगे जिसका उपयोग forms, games, dialogue boxes आदि जैसे कई अन्य एप्लिकेशन में किया जा सकता है। Tkinter में rounded buttons बनाने का सबसे अच्छा तरीका buttons की desired images का उपयोग करना और इसे frame में clickable button में बदलना है। यह PhotoImage(

  1. Python Tkinter में Canvas पर Image Center कैसे करें? Python Tkinter में Canvas पर Image Center कैसे करें?

    मान लीजिए हम Tkinter का उपयोग करके GUI-based एप्लिकेशन बना रहे हैं और हम Tkinter canvas में एक image load करना चाहते हैं। Default रूप से, canvas images को इसकी width और height के अनुसार load करता है। हालांकि, हम Direction value को anchor parameter में pass करके किसी भी direction (N, S, E, W, NS, EW,

  1. वर्डप्रेस में एक्सटर्नल इमेजेस को फीचर्ड इमेज के रूप में कैसे उपयोग करें वर्डप्रेस में एक्सटर्नल इमेजेस को फीचर्ड इमेज के रूप में कैसे उपयोग करें

    फीचर्ड इमेजेस किसी भी ब्लॉग पोस्ट का एक महत्वपूर्ण हिस्सा हैं। इमेजेस का उपयोग नवीनतम ब्लॉग के पेज, स्लाइडर्स, फेसबुक शेयर्स, और कई अन्य ऑनलाइन गतिविधियों पर किया जाएगा। लेकिन एक वर्डप्रेस ब्लॉग पोस्ट में फीचर्ड इमेज जोड़ने के लिए आपको इमेज को लाइब्रेरी में अपलोड करना होगा और वहां से इसे चुनना होगा