0% found this document useful (0 votes)
69 views

Computer: Python Tkinter Button

Button widgets are used to add buttons in Python applications. Buttons can display text or images and call functions when clicked. To create a button, the Button widget is used with options like text, image, command, width, height, and background color. Common button methods include flash() to flash the button colors and invoke() to call the attached callback function.

Uploaded by

Jer Felysse
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

Computer: Python Tkinter Button

Button widgets are used to add buttons in Python applications. Buttons can display text or images and call functions when clicked. To create a button, the Button widget is used with options like text, image, command, width, height, and background color. Common button methods include flash() to flash the button colors and invoke() to call the attached callback function.

Uploaded by

Jer Felysse
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Computer

Python Tkinter Button


Sources: Canvas,

The Button widget is used to add 5 command


buttons in a Python application. These
- Function or method to be
buttons can display text or images that
convey the purpose of the buttons. You can called when the button is
attach a function or a method to a button clicked.
which is called automatically when you click 6 fg
the button.
- Normal foreground (text)
SYNTAX color.
Here is the simple syntax to create this 7 font
widget
- Text font to be used for the
w = Button ( master, option=value, ... ) button's label.

PARAMETERS
Master - This represents the parent window.
8 height
Options − Here is the list of most commonly
used options for this widget. These options - Height of the button in text
can be used as key-value pairs separated by lines (for textual buttons) or
commas. pixels (for images).
SR# Option & Description 9 highlightcolor
1 activebackground - The color of the focus
- Background color when the highlight when the widget has
button is under the cursor. focus.

2 activeforeground 10 image

- Foreground color when the - Image to be displayed on the


button is under the cursor. button (instead of text).

3 bd 11 justify

- Border width in pixels. Default - How to show multiple text


is 2. lines: LEFT to left-justify each
line; CENTER to center them;
4 bg or RIGHT to right-justify.
- Normal background color.
12 padx
1
Causes the button to flash several
times between active and normal colors.
- Additional padding left and
Leaves the button in the state it was in
right of the text. originally. Ignored if the button is disabled.
13 pady invoke()
- Additional padding above and Calls the button's callback, and returns what
below the text. that function returns. Has no effect if the
button is disabled or there is no callback.
14 relief
Example:
- Relief specifies the type of the
border. Some of the values are import Tkinter
SUNKEN, RAISED, GROOVE,
and RIDGE. import tkMessageBox

15 state

- Set this option to DISABLED to top = Tkinter.Tk()


gray out the button and make
it unresponsive. Has the value
ACTIVE when the mouse is
over it. Default is NORMAL. def helloCallBack():

16 underline tkMessageBox.showinfo( "Hello Python",


"Hello World")
- Default is -1, meaning that no
character of the text on the
button will be underlined. If
nonnegative, the B = Tkinter.Button(top, text ="Hello",
command = helloCallBack)
corresponding text character
will be underlined.

17 width
B.pack()
- Width of the button in letters
top.mainloop()
(if displaying text) or pixels (if
displaying an image).

18 wraplength

- If this value is set to a positive


number, the text lines will be
wrapped to fit within this Output:
length.

METHODS
flash()

2
3

You might also like