我查看了所有其他问题和答案,但找不到适合我正在尝试做的事情。
代码:
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
当前屏幕图片:https ://i.imgur.com/P2B6E5y.png
我要弄清楚的第一件事是如何不明确说明右上角的 3 个文本小部件的大小。因为每个人的屏幕大小不一样。如果我没有明确说明大小,它们会扩展并且一切都会变得古怪(因为默认文本小部件很大)。我希望小部件自动缩小以适合列(与大灰色右下角文本小部件的宽度相同)。这甚至可能吗?
其次是让框架和小部件填满窗口中的所有空间。无论是全屏(如图所示)还是较小的窗口(并希望保持它们的大小相对)。窗户边缘有很多空白空间,我想摆脱它。我已经尝试了我能想到的一切,但我无法让他们填补那个空间。
我尝试将前 3 个小部件分别放在它们自己的框架中,限制相对于窗口大小的框架大小,并将小部件设置为填充该框架,但它不起作用。我曾经尝试过的代码: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
和结果图片:https ://i.imgur.com/IVnw65x.png
这是完整的代码:https ://pastebin.com/Gm2ePqFH 。我希望它看起来像在第一张图片中,而不必明确说明每个文本小部件的大小。我想让它相对于窗口保持相同的大小。