python 3.x - tkinter frames not working correctly -


i messing around tkinter module first time , not quite sure why widgets aren't being displayed in correct frame?

"text" , "entry" widgets should displayed @ top of top half of window , "button" , "output" widgets @ top of bottom half of window?

thanks

from tkinter import *  main_window = tk() main_window.title("x squared calculator") main_window.geometry("300x300") mw_frame1 = frame(main_window).pack() mw_frame2 = frame(main_window).pack()  text_widget1 = label(mw_frame1, text="please enter value:").pack(side=top) entry_widget1 = entry(mw_frame1, text="please enter value.").pack(side=top) button_widget1 = button(mw_frame2, text='press calculate!').pack(side=top) output_widget1 = label(mw_frame2, text="this number appear").pack(side=top)  main_window.mainloop() 

the problem this:

mw_frame1 = frame(main_window).pack() 

this sets mw_frame1 none, because pack() returns none. therefore, when try make other widgets children of widget, become children of root window. because children of root window, being packed in place don't expect.

move calls pack() separate statements:

mw_frame1 = frame(...) mw_frame2 = frame(...) ... mw_frame1.pack(...) mw_frame2.pack(...) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -