create a blue button in python

To create a blue button in python, you can use tkinter module to create a GUI application and then create a button with a blue color using the following code:

main.py
from tkinter import *

# Create a GUI window
root = Tk()

# Set window title
root.title("Blue Button")

# Set window size
root.geometry("200x100")

# Create button widget
btn = Button(root, text="Click me!", bg="blue", fg="white")

# Pack the button widget to show it in the window
btn.pack(pady=20)

# Run the GUI application
root.mainloop()
343 chars
20 lines

In the above code, we first import the tkinter module and create a GUI window using Tk() method. Then we set the title and size of the window using title() and geometry() methods.

Next, we create a button widget using Button() method and set its text to "Click me!" and background color as blue using the bg attribute. We also set the foreground color as white using the fg attribute.

Finally, we pack the button widget using pack() method and run the GUI application using mainloop() method.

gistlibby LogSnag