Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Popup Menu in Tkinter
Next article icon

Python provides many options for GUI (Graphical User Interface ) development.tkinter is the most commonly used method options apart from all other available alternatives. It is a standard method for developing GUI applications using Tk GUI toolkit. 

The steps involved in developing a basic Tkinter app are:

  1. Importing the Tkinter module.
  2. Creating the main window or the container.
  3. Insert as many widgets as you want to the main window.
  4. Apply the event Trigger on all the widgets.


The process of importing the Tkinter module is the same as importing any other module in Python.

import tkinter

Creating choose color dialog box using Tkinter


The Tkinter module has a package in it namedcolorchooser. This package of the Tkinter module helps in developing the color chooser dialog box. This package has a function namedaskcolor() that plays a major role.
 

askcolor()


This function belongs to thecolorchooserpackage of Tkinter module. The function helps in creating a color chooser dialog box. As soon as the function is called, it makes the color chooser dialogue box pop up. The function returns the hexadecimal code of the color selected by the user.
Syntax:
 

colorchooser.askcolor()


Example:
 

Python3
# Python program to create color chooser dialog box# importing tkinter modulefromtkinterimport*# importing the choosecolor packagefromtkinterimportcolorchooser# Function that will be invoked when the# button will be clicked in the main windowdefchoose_color():# variable to store hexadecimal code of colorcolor_code=colorchooser.askcolor(title="Choose color")print(color_code)root=Tk()button=Button(root,text="Select color",command=choose_color)button.pack()root.geometry("300x300")root.mainloop()

Output:
 

output1


 

output2


Note: The color chooser dialog box may vary for different operating systems.
 


Improve
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