#Libary# from tkinter import *
#Frame Window display window#
root = Tk()
root.title('Tic Tac Toe Start Window')
#root.iconbitmap('Images/tic_tac_toe.ico')
root.geometry('830x700')
root.configure(bg="#FFC300")
#Players label, Entry box Here can the players enter there name# #player 1#
L1=Label(text='Enter your name player 1: ', font=14)
L1.place(relx=0.0, rely=1.0, anchor='sw')
L1.configure(bg='#FFC300')
E1=Entry(root, font=14)
E1.place(relx=1.0, rely=1.0, anchor='w')
E1.configure(bg='#FFC300')
#player 2 here can player 2 enter there name#
L2=Label(text='Enter your name player 2: ', font=14)
L2.place(relx=1.0, rely=1.0, anchor='se')
L2.configure(bg='#FFC300')
E2=Entry(root, font=14)
E2.grid(row=0, column=3)
E2.configure(bg='#FFC300')
#Mainloop#
root.mainloop()
CodePudding user response:
As pointed out by @jasonharper, the choice of the layout management functions used in the code, can make a difference. Here using grid
to manage the entire layout is better to achieve the desired results(as mentioned in the OP), than to mix it up with the place
geometry manager.
The reason using grid
is a better option here compared to place is as grid can be used to easily define the rows and columns which allow you to render one widget below the other. place
on the other hand can be more effective in use cases wherein a widget has to exactly be rendered at certain coordinates on the screen.(
CodePudding user response:
It is more easier to put those labels and entries inside a frame and then put the frame at the bottom of the window.
import tkinter as tk
BG = '#FFC300'
FONT = 'Arial 14'
root = tk.Tk()
root.title('Tic Tac Toe Start Window')
root.geometry('830x700')
root.configure(bg=BG)
frame = tk.Frame(root, bg=BG)
frame.pack(side=tk.BOTTOM, fill=tk.X)
L1 = tk.Label(frame, text='Player 1:', font=FONT, bg=BG)
E1 = tk.Entry(frame, font=FONT, bg=BG)
L2 = tk.Label(frame, text='Player 2:', font=FONT, bg=BG)
E2 = tk.Entry(frame, font=FONT, bg=BG)
L1.pack(side=tk.LEFT)
E1.pack(side=tk.LEFT)
E2.pack(side=tk.RIGHT)
L2.pack(side=tk.RIGHT)
root.mainloop()