-2

the button wont go to postion i set it to when i run it could i get a little help please?

import tkinter
newbw=tkinter.Tk()  


def hub():    
    newbw.destroy()
    newbw=tkinter.Tk()
    newbw.attributes('-fullscreen', True)
    a=tkinter.Button(newbw, text="demonfight", command=dfpre)
    b=tkinter.Button(newbw, text="shop", command=shop)
    c=tkinter.Button(newbw, text="train", command=trainhub)
    d=tkinter.Button(newbw, text="quit", command=end)
    d.place(x=20, y=20)
    a.pack()
    b.pack()
    c.pack()
    d.pack()
  • You have called `d.place(...)` and `d.pack()`. Which one do you want? – acw1668 Feb 14 '20 at 15:38
  • i want to place it – arandomdosfile Feb 14 '20 at 15:40
  • wait so the pack dosent have to be there when i do place() ? – arandomdosfile Feb 14 '20 at 15:41
  • 1
    The later `pack()` will override former `place()`. So if you want `.place()`, remove `d.pack()`. – acw1668 Feb 14 '20 at 15:45
  • wait why is `d.place(x=20, y=20)` showing up on the left side i had it set to + + quadrent – arandomdosfile Feb 14 '20 at 15:47
  • @arandomdosfile Read [Why are multiple instances of Tk discouraged?](https://stackoverflow.com/questions/48045401/why-are-multiple-instances-of-tk-discouraged) and [gui layout using frames and grid](https://stackoverflow.com/questions/34276663/tkinter-gui-layout-using-frames-and-grid/34277295#34277295) – stovfl Feb 14 '20 at 16:03
  • @arandomdosfile Do you mean `+X+Y` inside `geometry(...)`? But since you have called `newbw.attributes('-fullscreen', True)`, the `geometry(..)` will be overrided. – acw1668 Feb 15 '20 at 02:34

1 Answers1

1

There are three geometry managers: pack, grid, and place. Using one of them is known as mapping a widget.

Pack and grid cannot be mixed. It's one or the other. Place can be mixed with pack or grid, but it's really (in my opinion) the last choice because placed widgets are not detected by the outer frame when it autosizes. So, because of the above, you were able to mix pack with place and not get an error.

Once you map something with a geometry manager, can you unmap and remap it. So, your first call to d.place() places the d widget. But then your second call to d.pack() overrides the place() and then packs the widget.

Because the default for pack() is side='top', you'll see your four widgets stacked, with a on top, down to d on the bottom.

Also, your app doesn't work right because you create a function hub(), but you never call it. Add:

if __name__ == '__main__':
    hub()

to the bottom of your program.

So, although your posted code is incomplete, try something more like this:

import tkinter

def hub():    
    newbw=tkinter.Tk()
    newbw.attributes('-fullscreen', True)
    a=tkinter.Button(newbw, text="demonfight", command=dfpre)
    b=tkinter.Button(newbw, text="shop", command=shop)
    c=tkinter.Button(newbw, text="train", command=trainhub)
    d=tkinter.Button(newbw, text="quit", command=end)
    #  d.place(x=20, y=20)
    a.pack()
    b.pack()
    c.pack()
    d.pack()

if __name__ == '__main__':
    hub()
GaryMBloom
  • 5,350
  • 1
  • 24
  • 32