Im using Tkinter framework to build a log in page but when i use the grid method to place entries and buttons inside a frame i got the login text and its entry in the same row,same thing for the password and its entries in other row, that's sounds good but the problem is they look sticky even if i gave a big difference to the row option
the distance between log in and pwd still the same.
you can get what i mean by looking at this pic
logbox = LabelFrame(root, text="Log In", font=("Corbel"),
highlightbackground=darg, highlightcolor=darg, highlightthickness=5, bg=darg, height=300, width=300)
logbox.grid_propagate(0)
logbox.pack(side=TOP)
tuser = Label(logbox, text="CIN", bg=darg, font=("arial", 9), fg="white")
y = 20
tuser.grid(row=0, column=1, pady=y)
enuser = ttk.Entry(logbox,)
enuser.grid(row=0, column=2, pady=y)
tpwd = Label(logbox, text="Password", bg=darg, font=("arial", 9), fg="white")
tpwd.grid(row=4, column=1)
enpwd = ttk.Entry(logbox,)
enpwd.grid(row=4, column=2)
logbut = ttk.Button(logbox, text="Log In", width=20)
logbut.grid(row=15, column=3,)
I've tried using the pady method, it kinda work but it's just like a temporary solution, I want to understand why the widgets are sticky.
I do not understand color darg
. You messed up row=4
and row=15
. You can used pady
. The easier way to do this.
Here is code:
from tkinter import *
from tkinter import ttk
root = Tk()
logbox = LabelFrame(root, text="Log In", font=("Corbel"),
highlightbackground='red', highlightcolor='red', highlightthickness=5, bg='red', height=300, width=300)
logbox.grid_propagate(0)
logbox.pack(side=TOP)
tuser = Label(logbox, text="CIN", bg='red', font=("arial", 9), fg="white")
tuser.grid(row=0, column=1)
enuser = ttk.Entry(logbox,)
enuser.grid(row=0, column=2)
tpwd = Label(logbox, text="Password", bg='red', font=("arial", 9), fg="white")
tpwd.grid(row=1, column=1, pady=5)
enpwd = ttk.Entry(logbox,)
enpwd.grid(row=1, column=2, pady=5)
logbut = ttk.Button(logbox, text="Log In", width=20)
logbut.grid(row=2, column=2, pady=10)
root.mainloop()
Result:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.