python - Tkinter code won't work -


i've been learning python e-book. right learning tkinter module

the book suggested running following code. however, not work should. ideas why?

from tkinter import *  window = tk() window.geometry("200x200")  my_frame = frame() my_frame.pack  button1 = button(my_frame, text = "i @ (100x150)") button1.place(x=100, y=150)  button2 = button(my_frame, text = "i @ (0 x 0)") button2.place(x=0, y=0, width=100, height=50)  window.mainloop() 

what should get: enter image description here

what get: enter image description here

after adding button1.pack() , button2.pack() this:

enter image description here

the smallest change make make code work so:

if going use frame, need give size so:

from tkinter import *  window = tk() window.geometry("300x300")  # note change line my_frame = frame(window, width=300, height=300)  my_frame.pack() # note parentheses added here  button1 = button(my_frame, text="i @ (100x150)") button1.place(x=100, y=150)  button2 = button(my_frame, text="i @ (0 x 0)") button2.place(x=0, y=0, width=100, height=50)  window.mainloop() 

also, pack() must function call, add parentheses


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -