As I understand it, this is what you want:
column 0 column 1
+-------------------------------------+--------------------------------+
| | |
row 0 | Passcode required to unlock system |
| | |
+-------------------------------------+--------------------------------+
row 1 | entry widget | Button widget |
+-------------------------------------+--------------------------------+
When using the grid manager, it really helps making a sketch with pencil and paper of the layout you want to achieve.
I like to put one widget per grid cell and then play with span, padding and row and column configuration (weight dictates if row/column will stretch and if so, their relative dimensions).
Here is your code modified for the layout shown above (read the comments):
from tkinter import *
import tkinter.font as tkFont
root = Tk()
def Password(root , unlock_message , access_camera):
activate_message = "SYSTEM ACTIVATED"
denied_message = "ACCESS DENIED"
size_letter = tkFont.Font(family = "Helvetica" , size = 24 , weight = "bold")
message_box = Label(root , text = "Passcode required to " + unlock_message + " system" , padx = 500 , font = size_letter)
# the label goes in row 0, column 0 and spans for 2 columns (right above the entry and the button)
# no sticky option spceified means it will be centered
message_box.grid(row = 0 , column = 0, columnspan=2)
# the entry widget goes in row 1 column 0
# it should stick to the right hand side (East). A horizontal padding of 5 provides some separation
input_box = Entry(root , show = "*" , width = 6 , font = ('Verdana' , 20) ).grid(row = 1 , column = 0, padx = 5, sticky='e')
# the button widget goes in row 1 column 1
# it should stick to the left hand side (West). A horizontal padding of 5 provides some separation
enter_password_button = Button(root , text = "Confirm" , pady = 8)
enter_password_button.grid(row = 1 , column = 1, padx = 5, sticky='w')
root.columnconfigure(0, weight=1) # columnn 0 should stretch -> weight=1
root.columnconfigure(1, weight=1) # columnn 1 should stretch -> weight=1
#root.rowconfigure(0, weight=0) # row 0 should not stretch -> weight=0 (this is the default, so this line is not actually needed)
root.geometry("1800x1100")
root.title("Vehicle app")
Password(root , "unlock" , True)
root.mainloop()
Note a potential error in your code, in line
enter_password_button = Button(root , text = "Confirm" , pady = 8).grid(row = 1 , column = 1)
You're actually assigning
None to
enter_password_button, because that's what .grid() returns.
If you want to use
enter_password_button later, you have to split the single line into two lines:
enter_password_button = Button(root , text = "Confirm" , pady = 8)
enter_password_button.grid(row = 1 , column = 1, padx = 5, sticky='w')