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:
what get:
after adding button1.pack() , button2.pack() this:
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
Post a Comment