tkinter python条目未显示

时间:2012-06-04 04:37:36

标签: python-3.x tkinter

我创建了一个带有标签和条目的表单。但由于某种原因,没有创建条目,

peoplegui.py

from tkinter import *
from tkinter.messagebox import showerror
import shelve
shelvename = 'class-shelve'
fieldnames = ('name','age','job','pay')

def makewidgets():
    global entries
    window = Tk()
    window.title('People Shelve')
    form = Frame(window)
    form.pack()
    entries = {}
    for (ix, label) in enumerate(('key',) + fieldnames):
        lab = Label(form, text=label)
        ent = Entry(form)
        lab.grid(row=ix, column=0)
        lab.grid(row=ix, column=1)
        entries[label] = ent
    Button(window, text="Fetch",  command=fetchRecord).pack(side=LEFT)
    Button(window, text="Update", command=updateRecord).pack(side=LEFT)
    Button(window, text="Quit",   command=window.quit).pack(side=RIGHT)    
    return window
def fetchRecord():
    print('In fetch')

def updateRecord():
    print('In update')


if __name__ == '__main__':
    window = makewidgets()
    window.mainloop()    

当我运行它时,会创建标签,但不会创建条目。

1 个答案:

答案 0 :(得分:1)

您忘记了对条目进行网格化。