I have this code:
from Tkinter import *
class App:
def __init__(self, master):
frame = Frame开发者_JAVA技巧(master)
frame.pack()
self.e = Entry(frame)
self.e.grid(row=0, column=0)
b = Button(frame, text='Search', command=self.well)
b.grid(row=0, column=1)
def well(self):
l0 = Label(Admin, text='first line')
l0.grid(row=1)
b0 = Button(Admin, text='F line S col')
b0.grid(row=1, column=1)
Admin = Tk()
app = App(Admin)
Admin.mainloop()
The ouput i get is THe Label and the Button on top of the Entry box. Does anyone know why this is? And how could i fix it to make it so that it is under the entry box?
What you want is to tie the label and button to the frame you've created in init, not the global Admin object. Replace frame = Frame(master)
with self.frame = Frame(master)
, then in well(), change references of Admin
to self.frame
.
精彩评论