-1

i've got this code where on the Startpage I have a menu on the top which gives a selection of buttons which are 'Home Task YourAdressess Payment', i've put them all in a red canvas, which is shaped like banner so they can stick out. I want the canvas to stretch if the user widens or shrinks the window, i achieved that but for some reason the canvas has just stuck in middle of the page rather than the top, please help. This part of the code is under 'Class 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()
Samuel Okasia
  • 95
  • 1
  • 6

1 Answers1

0

You need to set expand to False because you do not want it to expand to fill all extra space. It would also be best to include side="top" even though that's the default, because it makes your intention more clear.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685