Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python3 Tkinter-扩展一个框架以适应根窗口的问题_Python 3.x_Tkinter - Fatal编程技术网

Python 3.x Python3 Tkinter-扩展一个框架以适应根窗口的问题

Python 3.x Python3 Tkinter-扩展一个框架以适应根窗口的问题,python-3.x,tkinter,Python 3.x,Tkinter,你好(这是我的第一个问题) 我正在构建一个以Tkinter为GUI的应用程序。我希望多个帧展开以填充整个根窗口 使用下面的代码,我希望底部(绿色)帧可以一直扩展到顶部(青色)帧。相反,它停留在底部,并且在两个帧之间有一个“无帧”白色区域 这是我正在执行的代码(不影响框架布局的方法已缩短): 看起来您正在尝试创建一个包含多个选项卡的笔记本小部件 所以我建议你使用它,而不是自己重新发明 class CreateWindow: def __init__(self, master, screen):

你好(这是我的第一个问题)

我正在构建一个以Tkinter为GUI的应用程序。我希望多个帧展开以填充整个根窗口

使用下面的代码,我希望底部(绿色)帧可以一直扩展到顶部(青色)帧。相反,它停留在底部,并且在两个帧之间有一个“无帧”白色区域

这是我正在执行的代码(不影响框架布局的方法已缩短):


看起来您正在尝试创建一个包含多个选项卡的笔记本小部件

所以我建议你使用它,而不是自己重新发明

class CreateWindow:
def __init__(self, master, screen):
    self.master = master
    self.master.geometry('300x400')
    self.master.title("THE PROGRAM")
    self.screen = screen
    self.menu_bar = Menu(self.master)
    self.setup_menu = Menu(self.menu_bar)
    self.setup_bar()
    self.main_menu = Menu(self.menu_bar)
    self.main_bar()
    self.diary_menu = Menu(self.menu_bar)
    self.diary_bar()
    self.master.config(menu=self.menu_bar)
    # self.master.grid_columnconfigure(0, weight=1) # What is difference between these two and the two below?
    # self.master.grid_rowconfigure(0, weight=1)
    self.master.columnconfigure(0, weight=1)  
    self.master.rowconfigure(0, weight=1)
    self.top_menu(self.master)  # TODO: Make this menu actively do stuff
    if self.screen == "setup":
        setup = SetupScreen(self.master)
    elif self.screen == "main":
        setup = MainScreen(self.master)
    elif self.screen == "diary":
        setup = DiaryScreen(self.master)
    else:
        raise TypeError("wrong screen")

def setup_bar(self): ...

def main_bar(self): ...

def diary_bar(self): ...

def top_menu(self, window):  # Defines top frame : placeholder for future menu
    top = tk.Frame(window, bg='cyan', pady=5)
    top.grid(row=0, sticky='new')
    button = tk.Button(top, text="Setup", command=self.do_nothing)
    button.grid(row=0, column=0)
    button = tk.Button(top, text="Main", command=self.do_nothing)
    button.grid(row=0, column=1)
    button = tk.Button(top, text="Diary", command=self.do_nothing)
    button.grid(row=0, column=2)
    top.columnconfigure(0, weight=1)
    top.columnconfigure(1, weight=1)
    top.columnconfigure(2, weight=1)

def do_nothing(self): ...

def b_exit(self): ...


"""This class contains methods, that create and manage the setup screen. 
I want the green frame to expand all the way up to the cyan (top menu) """
class SetupScreen(CreateWindow):
def __init__(self, master):
    self.master = master
    self.menu = tk.Frame(self.master, bg='green')
    self.menu.grid(row=1, sticky='new')
    self.menu.columnconfigure(0, weight=1) # Again, what is difference between 'grid_'or not?
    self.menu.grid_rowconfigure(1, weight=1) #I have tried setting index to both 0 and 1, no difference
    self.create_buttons()

def create_buttons(self): ...

def personal_details(self): ...

def start_new(self):
    pass

if __name__ == "__main__":
files = FileHandler() #Class meant to be handling file operations - currently only sets a boolean to false, that makes the app start with setup screen
ap = files.active_program
print(ap)
root = tk.Tk()
if not files.active_program: #based on the boolean from FileHandler class, this starts the setup screen
    top_menu = CreateWindow(root, "setup")
else:
    top_menu = CreateWindow(root, "main")
root.mainloop()