Python Devlopment






Button



There are a number of widgets which you can put in your tkinter application. Some of the major widgets are explained below:

  • Button
  • Canvas
  • Checkbutton
  • Entry
  • Frame
  • Label
  • Listbox
  • Menubutton
  • Menu
  • Message
  • Radiobutton etc

Button:

To add a button in your application, this widget is used.
The general syntax is:

mybutton=Button(win, option=value)

win is the parameter used to represent the parent window.
There are number of options which are used to change the format of the Buttons. Number of options can be passed as parameters separated by commas. Some of them are listed below.

  • activebackground: to set the background color when button is under the cursor.
  • activeforeground: to set the foreground color when button is under the cursor.
  • bg: to set he normal background color.
  • command: to call a function.
  • font: to set the font on the button label.
  • image: to set the image on the button.
  • width: to set the width of the button.
  • height: to set the height of the button
Example:
from Tkinter import*
win=Tk()
win.title('My First GUI')
mybutton=Button(win,text="Click me")
mybutton.pack()
win.mainloop()