Tkinter is Python's standard GUI (Graphical User Interface) package.
It
is a cross-platform library, meaning applications built with Tkinter can
run on Windows, macOS, and Linux with a native look and feel. Tkinter
is included with most Python installations, so it's readily available for
use. It provides a variety of widgets such as buttons, labels, text boxes,
and menus, which can be used to create interactive user interfaces.
To get started with Tkinter, you typically import the tkinter module. A
basic Tkinter application involves creating a main window, adding
widgets to the window, and then starting the main event loop. The event
loop listens for user interactions, such as button clicks or key presses,
and triggers the corresponding actions in the application.
import tkinter as tk
# Create the main window
window = [Link]()
[Link]("Hello, World!")
# Create a label widget
label = [Link](window, text="Hello, World!")
[Link]()
# Start the main event loop
[Link]()
This code will create a window with the title "Hello, World!" and
display the text "Hello, World!" inside it.
Tkinter also offers different layout managers for arranging widgets
within a window, including pack(), grid(), and place(). These managers
provide flexibility in positioning and organizing the GUI elements.
While Tkinter is suitable for simple to moderately complex GUI
applications, it might not be the best choice for very large or feature-rich
applications that require advanced UI elements or customization
options. For such cases, other GUI frameworks like PyQt or Kivy might
be more appropriate.
1) import tkinter
m = [Link]()
[Link]()
2)
from tkinter import *
root = Tk()
w = Label(root, text='kalai!')
[Link]()
[Link]()
3) Button
A clickable button that can trigger an action. The general syntax is:
w=Button(master, option=value)
import tkinter as tk
r = [Link]()
[Link]('Counting Seconds')
button = [Link](r, text='Stop', width=25, command=[Link])
[Link]()
[Link]()
4) Entry
It is used to input the single line text entry from the user. For multi-line text
input, Text widget is used. The general syntax is:
w=Entry(master, option=value)
from tkinter import *
master = Tk()
Label(master, text='First Name').grid(row=0)
Label(master, text='Last Name').grid(row=1)
e1 = Entry(master)
e2 = Entry(master)
[Link](row=0, column=1)
[Link](row=1, column=1)
mainloop()
5) CheckButton
A checkbox can be toggled on or off. It can be linked to a variable to store its
state. The general syntax is:
w = CheckButton(master, option=value)
from tkinter import *
master = Tk()
var1 = IntVar()
Checkbutton(master, text='male', variable=var1).grid(row=0, sticky=W)
var2 = IntVar()
Checkbutton(master, text='female', variable=var2).grid(row=1,
sticky=W)
mainloop()
6)RadioButton
It allows the user to select one option from a set of choices. They are
grouped by sharing the same variable. The general syntax is:
w = RadioButton(master, option=value)
from tkinter import *
root = Tk()
v = IntVar()
Radiobutton(root, text='GfG', variable=v, value=1).pack(anchor=W)
Radiobutton(root, text='MIT', variable=v, value=2).pack(anchor=W)
mainloop()
7) Listbox
It displays a list of items from which a user can select one or more. The
general syntax is:
w = Listbox(master, option=value)
from tkinter import *
top = Tk()
Lb = Listbox(top)
[Link](1, 'Python')
[Link](2, 'Java')
[Link](3, 'C++')
[Link](4, 'Any other')
[Link]()
[Link]()
8) Scrollbar
It refers to the slide controller which will be used to implement listed widgets.
The general syntax is:
w = Scrollbar(master, option=value)
from tkinter import *
root = Tk()
scrollbar = Scrollbar(root)
[Link](side=RIGHT, fill=Y)
mylist = Listbox(root, yscrollcommand=[Link])
for line in range(100):
[Link](END, 'This is line number' + str(line))
[Link](side=LEFT, fill=BOTH)
[Link](command=[Link])
mainloop()
9) Menu
It is used to create all kinds of menus used by the application. The general
syntax is:
window.w = Menu(master, option=value)
from tkinter import *
root = Tk()
menu = Menu(root)
[Link](menu=menu)
filemenu = Menu(menu)
menu.add_cascade(label='File', menu=filemenu)
filemenu.add_command(label='New')
filemenu.add_command(label='Open...')
filemenu.add_separator()
filemenu.add_command(label='Exit', command=[Link])
helpmenu = Menu(menu)
menu.add_cascade(label='Help', menu=helpmenu)
helpmenu.add_command(label='About')
mainloop()
10)Message
It is a widget to display text messages with word wrapping. The general
syntax is:
w = Message(master, option=value)
from tkinter import *
main = Tk()
ourMessage = 'This is our Message'
messageVar = Message(main, text=ourMessage)
[Link](bg='lightgreen')
[Link]()
[Link]()