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

Tkinter में Button में Bitmap Images का उपयोग कैसे करें?

Tkinter में, हम images का उपयोग करके buttons बना और customize कर सकते हैं। इन images को Python PhotoImage(file) फंक्शन का उपयोग करके upload किया जा सकता है।

हालांकि, PhotoImage() केवल कुछ image types जैसे PNG, PPM, और GIF support करता है। इसके अलावा, हम BitMap images का उपयोग करके भी buttons बना सकते हैं। Bitmap image डॉट्स का एक समूह है जो matrix में aligned होते हैं और image के pixel को represent करते हैं। Tkinter में निम्न प्रकार के bitmap attributes उपलब्ध हैं:

  • "error"

  • "gray75"

  • "gray50"

  • "gray25"

  • "gray12"

  • "hourglass"

  • "info"

  • "questhead"

  • "question"

  • "warning"

उदाहरण

from tkinter import *

# Create an instance of tkinter frame
win = Tk()
win.geometry("700x300")
win.resizable(0, 0)

Button(win, relief=RAISED, bitmap="info").pack(pady=10)
Button(win, relief=RAISED, bitmap="gray50").pack(pady=10)
Button(win, relief=RAISED, bitmap="gray25").pack(pady=10)
Button(win, relief=RAISED, bitmap="gray12").pack(pady=10)
Button(win, relief=RAISED, bitmap="questhead").pack(pady=10)

win.mainloop()

आउटपुट

उपरोक्त code चलाने से निम्नानुसार bitmap buttons बनेंगे:

Tkinter में Button में Bitmap Images का उपयोग कैसे करें?

  1. Tkinter Python में Thread का उपयोग कैसे करें? Tkinter Python में Thread का उपयोग कैसे करें?

    Tkinter के साथ, हम Threading का उपयोग करके एक समय में multiple functions call कर सकते हैं। यह एप्लिकेशन में कुछ functions के asynchronous execution को प्रदान करता है। Python में thread का उपयोग करने के लिए, हम threading नामक module import कर सकते हैं और इसकी Thread class को subclass कर सकते हैं। अपन

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

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

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

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