Basic Tkinter Tutorial
Basic Tkinter Tutorial
To manipulate the window its size and position on the screen we use the
geometry method and to give it a title the title method.
Label
In the following code we will see how to create a label and place it in the window with
the pack method but the problem is that they are placed automatically.
In order to give it a precise location in the window, we will use another method.
called place instead of pack. Care must be taken as the measurements that
we use it in pixels and not in characters so we have to keep testing
until reaching the desired location.
Another way to position the labels is with the grib method. It is necessary to have
we will use the window as a grid. We will also use a
function to change the color and fill of the label and the sticky function for the
location of the text.
Text fields
For the text fields, we will need to create a variable of type StrinrVar()
to use the text field method, we will use the word entry to create
text fields, the text field has a size of 20 characters by
defect for which with the width property we can modify it, we use the
set method to input text.
lblNombre = Label(text='Name',font=('Agency'
FB',14)).place(x=10,y=50)
We create text fields
StringVar()
txtUsuario
Entry(window, textvariable=inputU).place(x=100, y=20)
inputN = StringVar()
txtName = Entry(window, textvariable=inputN, width =
30).place(x=100,y=60)
[Link]('LP0001')
Giancarlo Escobedo Valdivia
[Link]()
Buttons
For the creation of Buttons, we will use the Button method.
By adding events to the buttons, we will use the command property of the
next way:
We created two methods to help us.
Goodbye
font = ('Calibri',14)).place(x=10, y=180)
window = Tk()
[Link]('500x300+100+100')
Event Window with Buttons
We create the font tags
lblUsuario = Label(text='Usuario',font=('Verdana',14)).place(x=10,y=10)
Label(text='Name',font=('Agency FB',14)).place(x=10,y=50)
We create text fields
entradaU = StringVar()
txtUser = Entry(window,textvariable=inputU).place(x=100,y=20)
entradaN = StringVar()
txtName = Entry(window, textvariable=inputN, width =
30).place(x=100,y=60)
#We Create Buttons
Button(window, text='Greet', command=Greet,
font=('Arial',12),width = 15).place(x=300,y=20)
Button(window, text='Dismiss', command=Dismiss)
font=('Arial',12),width = 15).place(x=300,y=60)
[Link]()
List box
We will create a list box with some data.
window = Tk()
[Link]('700x600+0+0')
[Link]('Window with Lists')
Subject:
#we create a List
lstSubjects = Listbox(window, width=50)
[Link](0,'Basic Programming')
[Link](1, 'Object Oriented Programming')
[Link](2, 'Operating Systems')
[Link](3,'Programming in Python')
[Link](x=100,y=120)
We create a label, text box, and button
Label(window, text="Subjects:").place(x=100, y=20)
entradaL = StringVar()
txtMateria
Entry(window, textvariable=inputL, width=40).place(x=150, y=20)
add
add
[Link]()
Combo box