Création Bouton Tkinter avec événement onClick --click action-- En python 2.7 Version Windows7, Windows8, Windows10 et Python 3 version Windows7, Windows8, Windows10.
Pour créer une fenêtre Tkinter avec un bouton, utilisez l'exemple ci-dessous. Le programme entre mainloop () qui attend des événements (actions de l'utilisateur). Nous définissons le bouton qui a un rappel à la fonction callback (). master est la fenêtre racine, la fenêtre dans laquelle apparaîtra votre bouton.
To create a simple button in a window or a frame named parent:
class Button (parent, option = value, ...)
The constructor returns the new button widget. Its options are:
Settings:
activebackground - Background color when the mouse hovers over the button.
activeforeground - The color of the text when the mouse hovers over the button.
anchor - Specifies the position of the text on the button. See The Anchor System. For example, anchor = "ne" positions the text in the upper right (northeast) edge of the button.
borderwidth - (or bd) width of the button border; See Dimensions. By default, its value is 2 pixels.
background - (or bg) Background color.
bitmap - Name of one of the standard bitmaps to display on the button instead of the text.
command - Function or method to call when the button is clicked.
cursor - To indicate the mouse pointer to display when hovering over the button.
default - 'normal' is the default; use 'disabled' if the button must be disabled (grayed out and not responding to the click of the mouse).
disabledforeground - Text color when the button is disabled.
foreground - (or fg), Text color.
font - Font to use for button text.
height - Height of the button in number of lines (if the button has a text label) or in pixels (for images).
highlightbackground - Line color that indicates the button does not have focus.
highlightcolor - Line color that indicates the button has focus.
highlightthickness - Thickness of the focus line.
image - Image to display on the button (instead of the text).
justify - 'left', 'center' or 'right' to indicate the position of the text.
overrelief - The relief style to use when the mouse is over the button; the default is 'raised'. See Relief styles.
padx - Additional margin to the left and right of the text. See Dimensions for possible values.
pady - Additional margin at the top and bottom of the text.
relief - Specifies the type of relief applied to the button. (See Relief styles).
repeatdelay - See the next argument.
repeatinterval - Normally, a button is triggered only once when the user releases the mouse button. if you want the button to be triggered at regular intervals when the user holds the mouse button down, setting this option has a certain number of milliseconds to wait between each repetition and giving a value to the repeatdelay (ms) option to indicate a delay after which the button is triggered. For example, if repeatdelay = 500 and repeatinterval = 100, the button will be triggered after half a second and then retriggered every tenth of a second until the user releases the mouse button. If the user releases the button before the repeatdelay time, the button will fire normally.
state - Set this option to 'disabled' to gray out the button and make it inactive. Its value is "active" when the mouse is over the button and "normal" otherwise.
takefocus - Normally, using the Tab key, you can give the button focus (see Focus: Receiving keyboard input), and pressing the space bar has the same effect as clicking the button. You can set takefocus to zero to prevent this.
text - The text to display on the button.
textvariable - An instance of a StringVar () that will be associated with the button text. If the variable is modified, new text is displayed on the button. See Control variables: Values under widgets.
underline - Defaults to -1, indicating that no character in the button text is underlined. If its value is positive or zero, the corresponding character in the text is underlined. For example, underline = 1 indicates that the second character of the text will be underlined.
width - Width of the button in number of letters (if text is displayed) or in pixels (for an image).
wraplength - If a positive value is specified, the text is displayed with as many lines as necessary to fit within the width set by wraplength. For the different possible values, see Dimensions.
flash()
Causes the button to flash a few times. After that, it returns to its original state.
invoke ()
Calls the callback function associated with the command option and returns what that function returns. Has no effect if the button is disabled or if it has no callback function associated with it.