Tkinter Screen Not Centered - python

When I run the code the box appears in the top left, with most out of the view of the screen. I have gone over the code and cannot find what it causing this. Thanks for any help.
from tkinter import *
import sqlite3
import LoginMenu
class LogOn:
def __init__(self, window):
self.window = window
window.title("Log On")
window.state("zoomed")
h = self.window.winfo_height()
w = self.window.winfo_width()
Center_h = h/2
Center_w = w/2
self.FrameLogOn = Frame(window, bg = "PaleTurquoise1")
self.FrameLogOn.place(x = Center_w , y = Center_h, anchor = "center")
self.lbl_TrainerID = Label(self.FrameLogOn, text = "TrainerID:", bg = "PaleTurquoise1", font =("Arial","16"), width = 15)
self.lbl_TrainerID.grid(row = 0, column = 0)
self.ent_TrainerID = Entry(self.FrameLogOn, bg = "PaleTurquoise1", font =("Arial","16"))
self.ent_TrainerID.grid(row = 0, column = 1)
self.lbl_TrainerIDError = Label(self.FrameLogOn, text = "*TrainerID Not Found" ,bg = "PaleTurquoise1", font =("Arial","16"), fg = "PaleTurquoise1", width = 15)
self.lbl_TrainerIDError.grid(row = 0, column = 2)
self.lbl_Password = Label(self.FrameLogOn, text = "Password:" ,bg = "PaleTurquoise1", font =("Arial","16"), width = 15)
self.lbl_Password.grid(row = 1, column = 0)
self.ent_Password = Entry(self.FrameLogOn, bg = "PaleTurquoise1", font =("Arial","16"))
self.ent_Password.grid(row = 1, column = 1)
self.lbl_PasswordError = Label(self.FrameLogOn, text = "*Incorrect Password" ,bg = "PaleTurquoise1", font =("Arial","16"), fg = "PaleTurquoise1", width = 15)
self.lbl_PasswordError.grid(row = 1, column = 2)
self.btn_LogIn = Button(self.FrameLogOn, text = "Log In", bg = "PaleTurquoise1", font =("Arial", "16"), width = 15, command = self.LogIn)
self.btn_LogIn.grid(row = 2, column = 0, columnspan = 3)

Instead of using place which is a bit complex, how about using pack? As I understand this is what you want:
self.FrameLogOn = Frame(window, bg = "PaleTurquoise1")
self.FrameLogOn.pack(expand=True)
Just replace
h = self.window.winfo_height()
w = self.window.winfo_width()
Center_h = h/2
Center_w = w/2
self.FrameLogOn.place(x = Center_w , y = Center_h, anchor = "center")
with self.FrameLogOn.pack(expand=True).
expand=True option will keep inner frame in the center of the window.

Your window isn't managed by a geometry manager yet and therefore winfo_width() and winfo_height() will return 1. If you add window.update_idletasks() before h = self.window.winfo_height() then the problem is solved. So like this:
window.state("zoomed")
window.update_idletasks()
h = self.window.winfo_height()

place lets you use relative coordinates. relx=.5, rely=.5, anchor="center" places a widget exactly in the middle of its master.

Related

How to give a value in function to another function

In my app, settings button are initiating a window, in that window you insert your link and this link need to get back to main function and work with button, which open this link in browser
from tkinter import *
from tkinter import messagebox
def validate(P):
if len(P) == 0:
return True
elif len(P) <= 10:
return True
else:
return False
def validate_en(s):
pass
def close():
if messagebox.askokcancel("Close window", "Are u sure you want to exit?"):
web.destroy()
if __name__ == "__main__":
web = Tk()
web.configure(background = "black")
web.title("WebSaver")
web.geometry("600x400")
web.iconbitmap('icon.ico')
web.resizable(False, False)
web.protocol("WM_DELETE_WINDOW", close)
def main_content():
web.withdraw()
main = Toplevel(web)
main.title("Application")
main.geometry("800x600")
main.iconbitmap('icon.ico')
main.protocol("WM_DELETE_WINDOW", close)
main.resizable(False, False)
canvas = Canvas(main,width = "800", height = "600", highlightthickness = 0, bg =
"black")
canvas.pack(fill = BOTH, expand = True)
upper_text = Label(canvas, text= "TEXT", justify = "center", background =
"black", foreground = "white", font = "KacstDigital, 20", borderwidth = 2,
highlightthickness = 1, highlightbackground = "gray")
upper_text.pack(padx = 5)
def link_1():
pass
button_1 = Button(canvas, text = "First link", bg = "#293133", fg = "white", font
= "KacstDigital, 18", height = 2, width = 15, command = lambda: link_1)
button_1.place(x = 30, y = 150)
button_conf_1 = Button(canvas, text = "settings", bg = "#293133", fg = "white",
font = "KacstDigital, 7", width = 7, command = configurate_button_1)
button_conf_1.place(x = 198, y = 203)
def configurate_button_1():
def close():
conf.destroy()
def apply(link):
if (link.isspace() or link == ""):
messagebox.showwarning(title = "Error!", message = "Input is null")
else:
close()
return link
conf = Toplevel(web)
conf.title("Application")
conf.geometry("600x100")
conf.iconbitmap('icon.ico')
conf.protocol("WM_DELETE_WINDOW", close)
conf.resizable(False, False)
canvas = Canvas(conf, width = "600", height = "100", highlightthickness = 0, bg =
"black")
canvas.pack(fill = BOTH, expand = True)
vcmd = (canvas.register(validate_en), '%s')
link_text = Label(canvas, text= "Link: ", justify = "center", background =
"black", foreground = "white", font = "KacstDigital, 12", borderwidth = 2,
highlightthickness = 1, highlightbackground = "gray")
link_text.place(x = 5, y = 10)
link_entry = Entry(canvas, bg = "#293133", fg = "white", font = "KacstDigital,
14", width = 45, validate = "key", validatecommand = vcmd)
link_entry.place(x = 78, y = 10)
link_button = Button(canvas, text = "Confirm changes", bg = "#293133", fg =
"white", font = "KacstDigital, 14", height = 1, width = 20, command = lambda:
apply(link_entry.get()))
link_button.place(x = 15, y = 50)
main_content()
web.mainloop()
I need help with getting value from link_entry (in conf.button func.) and give this value to main_content to open this link from main_content.
Sorry for this strange option strings, idk how to get them at the right place

Empty window while running UI converted python code from Figma

To test Figma for the first time, I created a simple frame with two rectangles and renamed each to "TextBox" while using Figma. After that as per procedure i converted that to a python code and tried running it but it shows an empty window and no rectangles or text boxes. Any clues why is this happening. Here is the code i am running.
from tkinter import *
def btn_clicked():
print("Button Clicked")
window = Tk()
window.geometry("907x645")
window.configure(bg = "#ee1212")
canvas = Canvas(
window,
bg = "#ee1212",
height = 645,
width = 907,
bd = 0,
highlightthickness = 0,
relief = "ridge")
canvas.place(x = 0, y = 0)
entry0_img = PhotoImage(file = f"img_textBox0.png")
entry0_bg = canvas.create_image(
-188.0, 85.5,
image = entry0_img)
entry0 = Entry(
bd = 0,
bg = "#d9d9d9",
highlightthickness = 0)
entry0.place(
x = -338.0, y = 68,
width = 300.0,
height = 33)
entry1_img = PhotoImage(file = f"img_textBox1.png")
entry1_bg = canvas.create_image(
-188.0, 153.5,
image = entry1_img)
entry1 = Entry(
bd = 0,
bg = "#d9d9d9",
highlightthickness = 0)
entry1.place(
x = -338.0, y = 136,
width = 300.0,
height = 33)
background_img = PhotoImage(file = f"Background.png")
background = canvas.create_image(
-266.5, 20.5,
image=background_img)
window.resizable(False, False)
window.mainloop()
Float cannot be used for coordination.
entry0.place(
x = 33, y = 68,
width = 300,
height = 33)
and :
entry1.place(
x = 33, y = 136,
width = 300,
height = 33)

Why does my python program cut off a good section of my tkinter output?

I'm programming a simple application to help with tracking combat information for dnd using python and tkinter. I started with the input page and it worked fine, but when I started to use tabs to allow the user to access a help page, strangely it cut off about half of the original output, the only thing I changed is using ttk and my_frame 1 instead of root. I've tried changing .place to .grid and it worked to some degree, although instead it displayed the buttons in strange positions in front of the rest of the outputs. Then I tried adding blank lines on the help tag, this did work but it seems quite ineffective and time consuming. I can guess from this there's no space but the geometry was set to 500x500 which should be plenty. So I'm trying to figure out what's going wrong. Thanks for reading!
(Also it isn't quite complete yet hence why the next page function does something random)
This is the code:
import tkinter as tk
from tkinter import ttk
#Starting up tkinter
root = tk.Tk()
root.title("Dungeons and dragons combat manager")
root.geometry("500x500")
root.configure(background = "White")
#Initialise the arrays
player_details = []
overall_data = []
#help page
my_notebook = ttk.Notebook(root)
my_notebook.pack(pady = 15)
my_frame1 = tk.Frame(my_notebook, width = "500", height = "500")
my_frame1.grid(row = 0, column = 0, columnspan = 2, padx = 40, pady = 5)
my_frame2 = tk.Frame(my_notebook, width = 500, height = 500)
my_notebook.add(my_frame1, text = "Main")
my_notebook.add(my_frame2, text = "Help")
line1 = tk.Label(my_frame2, text = "Hello, welcome to the help page!", font = ('Times New Roman', 12)).grid(row = 0, column = 0, sticky = 'W')
line2 = tk.Label(my_frame2, text = "Most of the instructions will be given during application use", font = ('Times New Roman', 12)).grid(row = 1, column = 0, sticky = 'W')
line3 = tk.Label(my_frame2, text = "Please ensure all numerical inputs are given in integers", font = ('Times New Roman', 12)).grid(row = 2, column = 0, sticky = 'W')
line4 = tk.Label(my_frame2, text = "If any mistakes are made please press the restart button", font = ('Times New Roman', 12)).grid(row = 3, column = 0, sticky = 'W')
line5 = tk.Label(my_frame2, text = "Once the order is displayed initiative cannot be changed", font = ('Times New Roman', 12)).grid(row = 4, column = 0, sticky = 'W')
line6 = tk.Label(my_frame2, text = "However, health can be edited at any time", font = ('Times New Roman', 12)).grid(row = 5, column = 0, sticky = 'W')
line7 = tk.Label(my_frame2, text = "Good luck with your encounter!", font = ('Times New Roman', 12)).grid(row = 6, column = 0, sticky = 'W')
#main section
tk.Label(my_frame1, text = "Player details form", font = ('Times New Roman', 16)).grid(row = 0, column = 0, padx = 25, pady = 5)
#function definitions
def submit():
player_details = []
player_details.append(name.get())
player_details.append(health.get())
player_details.append(ac.get())
player_details.append(initiative.get())
overall_data.append(player_details)
print(str(overall_data))
player_num = tk.Label(root, text = "Inputting for Player :" + str(len(overall_data)+1), fg = 'White', bg = "Black")
player_num.place(x = 30, y = 210, width = 240, height = 25)
def clear():
name.delete(0, 'end')
health.delete(0, 'end')
ac.delete(0, 'end')
initiative.delete(0, 'end')
name.focus_set()
def next_page():
print("chicken")
#display
player_data = ['Name: ','Health: ','Armour Class: ','initiative: ']
labels = range(4)
for i in range(4):
bg_colour = "Black"
l = tk.Label(my_frame1,
text = player_data[i],
fg='White',
bg=bg_colour)
l.place(x = 20, y = 60 + i*30, width=120, height=25)
name = tk.Entry(my_frame1,width = 15,fg = "Black",bg = "White")
name.place(x = 150, y = 60, width = 120, height=25)
health = tk.Entry(my_frame1, width = 15,fg = "Black",bg = "White")
health.place(x = 150, y = 90, width = 120, height=25)
ac = tk.Entry(my_frame1, width = 15,fg = "Black",bg = "White")
ac.place(x = 150, y = 120, width = 120, height=25)
initiative = tk.Entry(my_frame1, width = 15,fg = "Black",bg = "White")
initiative.place(x = 150, y = 150, width = 120, height=25)
submit_button = tk.Button(my_frame1, text = "Submit", command = submit)
submit_button.place(x = 30, y = 180, width = 100, height = 25)
clear_button = tk.Button(my_frame1, text = "Clear", command = clear)
clear_button.place(x = 160, y = 180, width = 100, height = 25)
player_num = tk.Label(my_frame1, text = "Inputting for Player : 1", fg = 'White', bg = "Black")
player_num.place(x = 30, y = 210, width = 240, height = 25)
next_button = tk.Button(my_frame1, text = "Next", command = next_page)
next_button.place(x = 30, y = 240, width = 100, height = 25)
'''
It is because you haven't made the notebook large enough, and haven't requested that it expand to fill the available space. You're relying on the default size of the notebook, and you're putting more things in than will fit. Plus, you're using place instead of pack inside the notebook, and place won't cause the containing window to grow or shrink. This is one of the disadvantages to using place as a general purpose layout mechanism.
The easy solution is to use the options that pack supports, such as fill and expand, though without knowing what your full UI should look like it's hard to say if that's the correct solution or not.
my_notebook.pack(fill="both", expand=True)
Another solution would be to stop using place. If you use grid and/or pack, then the notebook will resize to fit its contents.

How to change Entry height in tkinter while using grid system and add text wraping?

I'm making an email sending gui application. I want to add an entry (messageEntry in my code) for entering the message. I want to change it's height so the message doesn't have to be entered in one line (I want to have text wraping). I tried using ipady, it does resize the entry but the message can still only be entered in one line (in the middle of the entry). Here is my code:
def sendMail(senderEmail, senderPassword):
global server
sendMailFont = ['Consolas', 10]
sendMailWindow = Tk()
sendMailWindow.title("Sendmail")
sendMailWindow.resizable(False, False)
sendMailWindow.focus_force()
# sendMailWindow.iconbitmap('info icon.ico')
sendMailWindow.config(bg = "#DCDCDC")
loggedInLabel = Label(sendMailWindow, font = (sendMailFont), text = "Logged in as {}".format(senderEmail), bg = "#DCDCDC")
loggedInLabel.grid(row = 0, column = 0)
subjectLabel = Label(sendMailWindow, font = (sendMailFont), text = "Subject", bg = "#DCDCDC")
subjectLabel.grid(row = 2, column = 0, sticky = "w")
subjectEntry = Entry(sendMailWindow, font = (sendMailFont), bg = "#FFFFFF", width = 37)
subjectEntry.grid(row = 3, column = 0, sticky = "w", ipady = 2)
messageLabel = Label(sendMailWindow, font = (sendMailFont), text = "Message", bg = "#DCDCDC")
messageLabel.grid(row = 5, column = 0, sticky = "w")
messageEntry = Entry(sendMailWindow, font = (sendMailFont), bg = "#FFFFFF", width = 37)
messageEntry.grid(row = 6, column = 0, sticky = "w")
hiddenLabel = Label(sendMailWindow, font = ('Consolas', 1), text = "", bg = "#DCDCDC")
hiddenLabel.grid(row = 1, column = 0, sticky = "we")
hiddenLabel = Label(sendMailWindow, font = ('Consolas', 10), text = "", bg = "#DCDCDC")
hiddenLabel.grid(row = 4, column = 0, sticky = "we")
sendMailWindow.mainloop()
You can use the tkinter.scrolledtext module like this:
from tkinter import *
from tkinter.scrolledtext import *
def sendMail(senderEmail, senderPassword):
global server
sendMailFont = ['Consolas', 10]
sendMailWindow = Tk()
sendMailWindow.title("Sendmail")
sendMailWindow.resizable(False, False)
sendMailWindow.focus_force()
# sendMailWindow.iconbitmap('info icon.ico')
sendMailWindow.config(bg = "#DCDCDC")
loggedInLabel = Label(sendMailWindow, font = (sendMailFont), text = "Logged in as {}".format(senderEmail), bg = "#DCDCDC")
loggedInLabel.grid(row = 0, column = 0)
subjectLabel = Label(sendMailWindow, font = (sendMailFont), text = "Subject", bg = "#DCDCDC")
subjectLabel.grid(row = 2, column = 0, sticky = "w")
subjectEntry = Entry(sendMailWindow, font = (sendMailFont), bg = "#FFFFFF", width = 37)
subjectEntry.grid(row = 3, column = 0, sticky = "w", ipady = 2)
messageLabel = Label(sendMailWindow, font = (sendMailFont), text = "Message", bg = "#DCDCDC")
messageLabel.grid(row = 5, column = 0, sticky = "w")
##########
messageEntry = ScrolledText(sendMailWindow, font = (sendMailFont), bg = "#FFFFFF", width = 37, height = 5)
messageEntry.grid(row = 6, column = 0, sticky = "w")
##########
sendMailWindow.mainloop()
This module is the tkinter.text module with a scroll bar. You can adjust his height.

Python tkinter downsizing widgets

I've looked at all the other questions and answers and couldn't find one that fit what I'm trying to do.
Code:
class GameWin:
def __init__(self, master):
self.master = master
self.master.title("Title")
self.main_frame = Frame(self.master, bd = 10, bg = uni_bg)
self.main_frame.grid()
self.left_frame = Frame(self.main_frame, bd = 10, bg = uni_bg)
self.left_frame.grid(column = 0, row = 0)
self.right_frame = Frame(self.main_frame, bd = 10, bg = uni_bg)
self.right_frame.grid(column = 1, row = 0)
self.right_frame.columnconfigure(0, weight = 1)
self.right_frame.rowconfigure(0, weight = 1)
self.right_frame.columnconfigure(1, weight = 1)
self.right_frame.rowconfigure(1, weight = 1)
self.web = Text(self.left_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bt_bg, fg = uni_fg)
self.web.grid(column = 0, row = 0, padx = 5, pady = 5)
self.output = Text(self.left_frame, font = (uni_font, 12), wrap = WORD, bg = "black", fg = uni_fg)
self.output.grid(column = 0, row = 1, padx = 5, pady = 5, sticky = "ew")
self.output.configure(state = "disabled")
self.input = Entry(self.left_frame, font = (uni_font, 12))
self.input.grid(column = 0, row = 2, sticky = "ew")
self.input.bind('<Return>', self.submit)
self.notepad = Text(self.right_frame, font = (uni_font, 12), wrap = WORD, bg = uni_fg, fg = "black", width = 42)
self.notepad.grid(column = 0, row = 0, pady = 5, rowspan = 2)
self.sys_info = Text(self.right_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bg, fg = uni_fg, width = 35, height = 11, bd = 0)
self.sys_info.tag_configure('center', justify='center')
self.sys_info.grid(column = 1, row = 0, pady = 5)
self.sys_info.insert(END, "NAME", "center")
self.sys_info.configure(state = "disabled")
self.trace = Text(self.right_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bg, fg = uni_fg, width = 35, height = 11)
self.trace.grid(column = 1, row = 1, pady = 5)
self.email = Text(self.right_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bt_bg, fg = uni_fg)
self.email.grid(column = 0, row = 2, pady = 5, columnspan = 2)
self.email.configure(state = "disabled")
self.respond = Entry(self.right_frame, font = (uni_font, 12))
self.respond.grid(column = 0, row = 3, columnspan = 2, sticky = "ew")
self.respond.bind('<Return>', self.do_respond)
def submit(self, event):
self.output.configure(state = "normal")
self.output.configure(state = "disabled")
pass
def do_respond(self, event):
pass
Image of current screen: https://i.imgur.com/P2B6E5y.png
First thing I'm trying to figure out is how to not explicitly state the size of the 3 text widgets in the top right. Because everyone's screen is differently sized. If I don't explicitly state the size, they expand and everything goes wacko (since the default text widget is big). I want the widgets to automatically downscale to fit within the column (the same width as the big grey bottom right text widget). Is this even possible?
Second is for the frames and widgets to fill up all the space in the window. Whether it's fullscreen (like in the pic) or a smaller window (and hopefully keep their size relative to each other). There's a lot of empty space at the edges of the window and I want to get rid of that. I've tried everything I can think of but I can't get them to fill that space.
I tried putting the top 3 widgets each in their own frame, limiting the size of the frames relative to the window size, and setting the widgets to fill that frame but it doesn't work. Code I used to try this: https://pastebin.com/3YWK9Xg2
class GameWin:
def __init__(self, master):
self.master = master
self.master.title("Hacker")
win_width = self.master.winfo_width()
win_height = self.master.winfo_height()
self.main_frame = Frame(self.master, bd = 10, bg = uni_bg)
self.main_frame.grid(sticky = "nsew")
self.left_frame = Frame(self.main_frame, bd = 10, bg = uni_bg, height = int(win_height), width = int(win_width/2))
self.left_frame.grid(column = 0, row = 0, rowspan = 3)
self.left_frame.grid_propagate(False)
self.note_frame = Frame(self.main_frame, bd = 10, bg = uni_bg, height = int(win_height/2), width = int(win_width/4))
self.note_frame.grid(column = 1, row = 0, rowspan = 2, sticky = "n")
self.note_frame.grid_propagate(False)
self.sys_frame = Frame(self.main_frame, bd = 10, bg = uni_bg, height = int(win_height/4), width = int(win_width/4))
self.sys_frame.grid(column = 2, row = 0, sticky = "n")
self.sys_frame.grid_propagate(False)
self.trace_frame = Frame(self.main_frame, bd = 10, bg = uni_bg, height = int(win_height/4), width = int(win_width/4))
self.trace_frame.grid(column = 2, row = 1, sticky = "n")
self.trace_frame.grid_propagate(False)
self.bottom_right_frame = Frame(self.main_frame, bd = 10, bg = uni_bg, height = int(win_height/2), width = int(win_width/2))
self.bottom_right_frame.grid(column = 1, row = 2, columnspan = 2)
self.bottom_right_frame.grid_propagate(False)
self.web = Text(self.left_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bt_bg, fg = uni_fg)
self.web.grid(column = 0, row = 0, padx = 5, pady = 5)
self.output = Text(self.left_frame, font = (uni_font, 12), wrap = WORD, bg = "black", fg = uni_fg)
self.output.grid(column = 0, row = 1, padx = 5, pady = 5, sticky = "ew")
self.input = Entry(self.left_frame, font = (uni_font, 12))
self.input.grid(column = 0, row = 2, sticky = "ew")
self.input.bind('<Return>', self.submit)
self.notepad = Text(self.note_frame, font = (uni_font, 12), wrap = WORD, bg = uni_fg, fg = "black")
self.notepad.pack(fill = BOTH, expand = YES)
self.sys_info = Text(self.sys_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bg, fg = uni_fg)
self.sys_info.tag_configure('center', justify='center')
self.sys_info.grid(sticky = "nsew")
self.sys_info.insert(END, "NAME", "center")
self.sys_info.configure(state = "disabled")
self.trace = Text(self.trace_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bg, fg = uni_fg)
self.trace.grid(sticky = "nsew")
self.email = Text(self.bottom_right_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bt_bg, fg = uni_fg)
self.email.grid(row = 0, pady = 5, columnspan = 2, sticky = "nsew")
self.email.configure(state = "disabled")
self.respond = Entry(self.bottom_right_frame, font = (uni_font, 12))
self.respond.grid(row = 1, columnspan = 2, sticky = "ew")
self.respond.bind('<Return>', self.do_respond)
def submit(self, event):
self.output.configure(state = "normal")
self.output.configure(state = "disabled")
def do_respond(self, event):
pass
and picture of the result: https://i.imgur.com/IVnw65x.png
Here is the full code: https://pastebin.com/Gm2ePqFH. I want it to look like it is in the first picture, without having to explicitly state the size of each text widget. And I want to get it to all stay the same size relative to the window.
If you want widgets to shrink down to the size of the column, the strategy that has worked best for me is to make the widget very small and then use the layout manager (pack, place, or grid) make them bigger to fit. You can either make the widget 1x1 if that's truly a minimum size you will accept, or you can set it to what you think the absolute minimum should be (for example, 4 lines of 20 characters, 20 lines of 10 characters, etc).
So, start by making those widgets as small as possible.
Next, make sure you use the sticky attribute so that the widgets grow to fill their allotted space. You also need to make sure you use the sticky attribute for self.right_frame so that it fills its space too.
Finally, make sure that you call rowconfigure and columnconfigure to set a positive weight on any widget that has children managed by grid. You aren't doing that for self.master, nor are you doing it for self.left_frame and self.right_frame
As a rule of thumb, if you're only putting one or two widgets in a frame and you want those widgets to fill the frame, it's much better to use pack than grid, simply because you don't have to remember to give the rows and columns weights.
For example, you can use pack to manage the left and right frames. You can probably use pack to put GameWin inside of its master, too.
Also, don't try to solve all of your layout problems at once. In your case, I would tackle the problem like this:
Start with just your mainframe and get it so that it fills the containing window. Make sure you manually resize the window to watch it grow and shrink.
Next, add your left and right frames. Make sure they grow and shrink to fit mainframe.
Next, focus on just the widgets in the left frame. Add them, and make sure they shrink and fit.
Then, focus on the right frame. Add them, and make sure they shrink and fit.
Finally, a word of advice. Group your calls to grid together. As your code is written now, you need to fix a whole bunch of lines scattered over the entire file. With some reorganization, almost all of the lines of code you need to change will be in one block of code.
For example, instead of this:
self.web = Text(...)
self.web.grid(...)
self.output = Text(...)
self.output.grid(...)
self.input = Text(...)
self.input.grid(...)
self.notepad = Text(...)
self.notepad.grid(...)
Do this:
self.web = Text(...)
self.output = Text(...)
self.input = Text(...)
self.notepad = Text(...)
self.web.grid(...)
self.output.grid(...)
self.input.grid(...)
self.notepad.grid(...)
With that, at a glance you can answer the question "how are my widgets defined?", and "how are my widgets laid out". With the way you have it now, those questions are very difficult to answer.

Categories

Resources