Rowly
Rowly

Reputation: 23

Creating an entry table on TKinter

How would I go about creating a table on Tkinter that can take in entries from the keyboard?

So far, I have created a Tkinter frame.

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()

Upvotes: 2

Views: 9915

Answers (1)

Al.Sal
Al.Sal

Reputation: 984

This works in 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()

To access an entry (either to populate it or get the value of it) find the index of it in the entries dict. For example:

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

Upvotes: 1

Related Questions