在页面顶部展开画布

问题描述 投票:-1回答:1

我有这样的代码,在Startpage上,我有一个菜单在顶部,它提供了一个按钮的选择,这是 "主页任务你的地址付款",我已经把他们都在一个红色的画布,这是形状像横幅,所以他们可以坚持。我想让画布在用户扩大或缩小窗口时伸展,我做到了,但由于某些原因,画布只是停留在页面的中间而不是顶部,请帮助我。这部分代码在 "类StartPage(tk.Frame) "下。

from tkinter import *
import time
import tkinter as tk
LARGE_FONT= ("Verdana", 12)

class SeaofBTCapp(tk.Tk):

    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        container = tk.Frame(self)
        container.pack(side="top", fill="both", expand = True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}

        for F in (StartPage, HypeExtractor, Task, Payment, YourAdressess):

            frame = F(container, self)

            self.frames[F] = frame

            frame.grid(row=0, column = 0, sticky="nsew")

        self.show_frame(StartPage)

    def show_frame(self, cont):
        #for frame in self.frames.values():
            #frame.grid_remove()

        frame = self.frames[cont]
        frame.tkraise()
        frame.winfo_toplevel().geometry("1024x720")

#The Bit 
class StartPage(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

        #The Bit I Need Help On 
        c = Canvas(self, height=50, width=1024, bg="red")
        c.pack(fill = 'x',expand = True)
        homebutton = tk.Button(self, text='Home', command=lambda: controller.show_frame(HypeExtractor))
        homebutton_window = c.create_window(10, 12.5, anchor=tk.NW, window=homebutton)
        taskbutton = tk.Button(self, text='Task', command=lambda: controller.show_frame(Task))
        taskbutton_window = c.create_window(104, 12.5, anchor=tk.NW, window=taskbutton)
        adressbutton = tk.Button(self, text='Your Adressess', command=lambda: controller.show_frame(YourAdressess))
        adressbutton_window = c.create_window(196, 12.5, anchor=tk.NW, window=adressbutton)
        paymentbutton = tk.Button(self, text='Payment', command=lambda: controller.show_frame(Payment))
        paymentbutton_window = c.create_window(323, 12.5, anchor=tk.NW, window=paymentbutton)

        # usernameentry.delete(0, END)
        # passwordnameentry.delete(0, END)

class HypeExtractor(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

class Task(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

class YourAdressess(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
class Payment(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

app = SeaofBTCapp()
app.mainloop()
python oop tkinter pycharm tk
1个回答
0
投票

你需要设置 expandFalse 因为你不希望它膨胀到填满所有多余的空间。最好还包括 side="top" 尽管这是默认的,因为它使你的意图更加明确。

© www.soinside.com 2019 - 2024. All rights reserved.