Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
How do you create a Button on a tkinter Canvas?
Next article icon

Prerequisite:Python GUI – tkinter

Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python.

Abitmapis an array of binary data representing the values of pixels in an image. AGIF is an example of a graphics image file that has a bitmap.

To create a bitmap image 'bitmap' attribute of the button() function is used display. It can take the following values:

  • error
  • gray75
  • gray50
  • gray25
  • gray12
  • hourglass
  • info
  • questhead
  • question
  • warning

Syntax:

Button(..., bitmap="<value>")

Approach 1:

  • Import module
  • Create object
  • Create buttons 
  • Execute code

Program:

Python3
# Import Modulefromtkinterimport*# Create Objectsroot=Tk()# ButtonsButton(root,relief=RAISED,bitmap="error").pack(pady=10)Button(root,relief=RAISED,bitmap="hourglass").pack(pady=10)Button(root,relief=RAISED,bitmap="info").pack(pady=10)Button(root,relief=RAISED,bitmap="question").pack(pady=10)Button(root,relief=RAISED,bitmap="warning").pack(pady=10)Button(root,relief=RAISED,bitmap="gray75").pack(pady=10)Button(root,relief=RAISED,bitmap="gray50").pack(pady=10)Button(root,relief=RAISED,bitmap="gray25").pack(pady=10)Button(root,relief=RAISED,bitmap="gray12").pack(pady=10)Button(root,relief=RAISED,bitmap="questhead").pack(pady=10)# Execute Tkinterroot.mainloop()

Output:

Approach 2:

In this method, we will create a list of bitmaps and iterate through all bitmaps while passing them to button() function.

  • Import module
  • Create object
  • Create bitmap list
  • Iterate through the list
  • Create buttons while iterating
  • Execute code

Program:

Python3
# Import Modulefromtkinterimport*# Create Objectsroot=Tk()# Create Bitmaps Listbitmaps=["error","gray75","gray50","gray25","gray12","hourglass","info","questhead","question","warning"]# Iterate through all bitmap listforbitinbitmaps:Button(root,relief=RAISED,bitmap=bit).pack(pady=10)# Execute Tkinterroot.mainloop()

Output:


Improve
Article Tags :
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp