在TKinter上创建一个条目表

时间:2013-08-06 21:49:15

标签: python tkinter

我如何在Tkinter上创建一个可以从键盘输入条目的表?

到目前为止,我已经创建了一个Tkinter框架。

import Tkinter as tk
import numpy as np
import scipy as sp


class app(tk.Frame):
def __init__(self, master = None):
    tk.Frame.__init__(self, master)
    self.grid(ipadx = 300, ipady = 300)


prog = app()
prog.master.title('Sudoku')
prog.mainloop()

1 个答案:

答案 0 :(得分:1)

这适用于python 2.7:

from Tkinter import *
from string import ascii_lowercase

class app(Frame):
    def __init__(self, master = None):
        Frame.__init__(self, master)
        self.grid()
        self.create_widgets()

    def create_widgets(self):
        self.entries = {}
        self.tableheight = 9
        self.tablewidth = 9
        counter = 0
        for row in xrange(self.tableheight):
            for column in xrange(self.tablewidth):
                self.entries[counter] = Entry(self, width=5)
                self.entries[counter].grid(row=row, column=column)
                counter += 1

prog = app()
prog.master.title('Sudoku')
prog.mainloop()

要访问条目(填充它或获取它的值),请在条目dict中找到它的索引。例如:

self.entries[15].insert(0, '15')