Variable Classes In TKinter

Variable Classes



- Variables can be used with most entry widgets to track changes to the entered value. 
-  The Checkbutton and Radiobutton widgets require variables to work properly. 
- Some widgets (like text entry widgets, radio buttons and so on) can be connected directly to application variables by using special options: variable, textvariable, onvalue, offvalue, and value.

-  Create a Tkinter variable: 
  - x = StringVar() # Holds a string; default value "" 
  - x = IntVar() # Holds an integer; default value 0 
  - x = DoubleVar() # Holds a float; default value 0.0 
  - x = BooleanVar() # Holds a boolean, returns 0 for False and 1 for True

Example-: 
var = StringVar() 
var.set("hello") #to set the value, call the set method

Tkinter Widgets

- Tkinter provides various controls, such as buttons, labels and text boxes used in a GUI application. - - These controls are commonly called widgets. 




-  Label
-  Button 
-  Canvas 
-  combo-box 
-  frame  
- level 
-  check-button  
- entry  
- level-frame  
- menu  
- list 
- box  
- menu button 
-  message
- tk_optoinMenu  
- progress-bar 
-  radio button 
-  scroll bar 
-  Separator 
-  tree-view and many more...


Explain In Details:-

Label:- A label is a widget that displays text or images, typically that the user will just view does not interact with. Labels are used for such things as identifying controls or other parts of the user interface, providing textual feedback or results, etc.

Syntax:-
w = Label ( master, option, ... ) 
  master − represents the parent window. 
  options − list of commonly used options for this widget.



Button:- The Button widget is used to add buttons in a Python application. These buttons can display text or images that convey the purpose of the buttons

Syntax:-
w = Button ( master, option=value, ... ) 
  master − represents the parent window. 
  options − list of commonly used options for this widget.





Checkbutton:- The Checkbutton widget is used to display a number of options to a user as toggle buttons. The user can then select one or more options by clicking the button corresponding to each option.
- Checkboxes are shown on the screen as square boxes. 
-  A Checkbox has two states: on or off.

Syntax:-
w = Checkbutton ( master, option, ... )
   master − represents the parent window. 
   options − list of commonly used options for this widget.

Radiobutton:- A radio button, sometimes called option button, is a graphical user interface element of Tkinter, which allows the user to choose (exactly) one of a predefined set of options.

Syntax:-
w = Radiobutton ( master, option, ...  )
   master − represents the parent window. 
   options − list of commonly used options for this widget.

Entry:- The Entry widget is used to accept single-line text strings from a user. Entry widgets are the basic widgets of Tkinter used to get input, i.e. text strings, from the user of an application.

Syntax:- 
w = Entry( master, option, ... ) 
  master − represents the parent window. 
  options − list of commonly used options for this widget.

Text:- A text widget is used for multi-line text area. The Text widget provides formatted text display. It allows you to display and edit text with various styles and attributes. It allows user to edit a multiline text and format the way it has to be displayed, such as changing its color and font.

Syntax:-
w = Text( master, option, ... ) 
  master − represents the parent window. 
  options − list of commonly used options for this widget.




Check out Our Python Post In Just One Click


Don't Forget to Share your Opinion About This post in Comment Section, Your One Comment Will Not only Make Our day But will Make our Year. And Do mention Of you have any ideas for our Blog:)

Post a Comment

10 Comments