python - My buttons sit side by side in my Home window but they appear in the middle. How do I get them higher up? -


enter image description here

i having similar issue shop class too. first button (teapops) want buttons on home window , shop window (except home) if use:

      button1.pack(side=top, anchor=nw, padx=10, pady=60, expand=no)       button2.pack(side=top, anchor=nw, padx=30, pady=60, expand=no)       button3.pack(side=top, anchor=nw, padx=60, pady=60, expand=no) 

enter image description here

but others appear lower , lower , don't have idea why except maybe have issue frames?

if use this,

      button1.pack(side=left, anchor=nw, fill=both, expand=1)       button2.pack(side=left, anchor=nw, fill=both, expand=1)       button3.pack(side=left, anchor=nw, fill=both, expand=1) 

then buttons appear side side in middle of screen again on home screen:

enter image description here

can please explain me whats going on? think there basics frames not understanding. please help!!!!

import tkinter tk    tkinter import *  title_font = (“helvetica”, 18, “bold”) credits_font = (“helvetica”, 12, “bold”)  class app(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 = {}       f in (home, my_plnts, jrnl, shop, mail):           page_name = f.__name__           frame = f(parent=container, controller=self)           self.frames[page_name] = frame            frame.grid(row=0, column=0, sticky=“nsew”)        self.show_frame(“home”)    def show_frame(self, page_name):        frame = self.frames[page_name]       frame.tkraise()  class home(tk.frame):    def __init__(self, parent, controller):       tk.frame.__init__(self, parent)       self.controller = controller        home.configure(self, background=’#ade5ad’)        label = tk.label(self, text=“welcome home, maebert!”, background=’#ade5ad’, font=title_font)       label.pack(side=“top”, fill=“x”, pady=10)        button1 = tk.button(self, text=“my plnts”,                           command=lambda: controller.show_frame(“my_plnts”))       button2 = tk.button(self, text=“jrnl”,                           command=lambda: controller.show_frame(“jrnl”))       button3 = tk.button(self, text=“shop”,                           command=lambda: controller.show_frame(“shop”))       button4 = tk.button(self, text=“mail”,                           command=lambda: controller.show_frame(“mail”))       button1.pack(side=left, padx=60)       button2.pack(side=left, padx=60)       button3.pack(side=left, padx=60)       button4.pack(side=left, padx=60)  class my_plnts(tk.frame):    def __init__(self, parent, controller):       tk.frame.__init__(self, parent)       self.controller = controller        my_plnts.configure(self, background=’#ade5ad’)        label = tk.label(self, text=“my plnts”, background=’#ade5ad’, font=title_font)       label.pack(side=“top”, anchor=nw, fill=“x”, pady=10)       button = tk.button(self, text=“back home”,                          command=lambda: controller.show_frame(“home”))       button.pack(side=“top”, anchor=ne)  class jrnl(tk.frame):    def __init__(self, parent, controller):       tk.frame.__init__(self, parent)       self.controller = controller        jrnl.configure(self, background=’#ade5ad’)        label = tk.label(self, text=“jrnl”, background=’#ade5ad’, font=title_font)       label.pack(side=“top”, fill=“x”, pady=10)       button = tk.button(self, text=“back home”,                          command=lambda: controller.show_frame(“home”))       button.pack(side=“top”, anchor=ne)  class shop(tk.frame):    def __init__(self, parent, controller):       tk.frame.__init__(self, parent)       self.controller = controller        shop.configure(self, background=’#ade5ad’)        label = tk.label(self, text=“shop”, background=’#ade5ad’, font=title_font)       label.pack(side=“top”, fill=“x”, pady=10)        label = tk.label(self, text=“more @ www.gfc.com”, background=’#ade5ad’, font=credits_font)       label.pack(side=“bottom”, fill=“x”, pady=10)        button = tk.button(self, text=“back home”,                          command=lambda: controller.show_frame(“home”))        button1 = tk.button(self, text=“teapops”,                           command=lambda: controller.show_frame(“teapops”))       button2 = tk.button(self, text=“plants”,                           command=lambda: controller.show_frame(“plants”))       button3 = tk.button(self, text=“nail polish”,                           command=lambda: controller.show_frame(“nail_polish”))        button.pack(side=“top”, anchor=ne)        button1.pack(side=left, anchor=nw, fill=both, expand=1)       button2.pack(side=left, anchor=nw, fill=both, expand=1)       button3.pack(side=left, anchor=nw, fill=both, expand=1)        “”“       button1.pack(side=top, anchor=nw, padx=10, pady=60, expand=no)       button2.pack(side=top, anchor=nw, padx=30, pady=60, expand=no)       button3.pack(side=top, anchor=nw, padx=60, pady=60, expand=no) ”“”  class mail(tk.frame):    def __init__(self, parent, controller):       tk.frame.__init__(self, parent)       self.controller = controller        mail.configure(self, background=’#ade5ad’)        label = tk.label(self, text=“mail”, background=’#ade5ad’, font=title_font)       label.pack(side=“top”, fill=“x”, pady=10)       button = tk.button(self, text=“back home”,                          command=lambda: controller.show_frame(“home”))       button.pack(side=“top”, anchor=ne)  if __name__ == “__main__”:   app = app()   app.minsize(300,300)   app.geometry(“800x800”)   app.mainloop() 

i built below program demonstrate how .pack() method works, please feel free play around different options , see how each affects output:

from tkinter import *  root = tk() top = toplevel() top.withdraw() var1 = stringvar(root) var1.set("top") var2 = stringvar(root) var2.set("none") var4 = stringvar(root) var4.set("center") var3 = booleanvar(root)  def command(top, var1, var3, var2):     top.destroy()     top = toplevel()     top.geometry("500x500")     label(top, text="welcome home").pack()     button(top, text="button1").pack(side=var1.get(), fill=var2.get(), expand=var3.get(), anchor=var4.get())     button(top, text="button2").pack(side=var1.get(), fill=var2.get(), expand=var3.get(), anchor=var4.get())     button(top, text="button3").pack(side=var1.get(), fill=var2.get(), expand=var3.get(), anchor=var4.get())     button(top, text="button4").pack(side=var1.get(), fill=var2.get(), expand=var3.get(), anchor=var4.get())  option1 = optionmenu(root, var1, "top", "left", "bottom", "right") check1 = checkbutton(root, variable=var3, text="expand?") option2 = optionmenu(root, var2, "none", "x", "y", "both") option3 = optionmenu(root, var4, "center", "n", "ne", "e", "se", "s", "sw", "w", "nw") button1 = button(root, text="render", command=lambda:command(top, var1, var3, var2))  option1.pack() check1.pack() option2.pack() option3.pack() button1.pack()  root.mainloop() 

this should show how different options affect results of .pack().

more point believe effect looking can achieved using .pack(side="left", expand="true", fill="x", anchor="n").


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -