Created
March 14, 2019 20:18
-
-
Save jvoytech/eefc7c711d0776add474a827a40150be to your computer and use it in GitHub Desktop.
simple Tkinter excel spreadsheet cells
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter as tk | |
app = tk.Tk() | |
class Excel(tk.Frame): | |
def __init__(self, master, rows, columns, width): | |
super().__init__(master) | |
for i in range(columns): | |
self.make_entry(0, i+1, width, f'C{i}', False) | |
for row in range(rows): | |
self.make_entry(row+1, 0, 5, f'R{row}', False) | |
for column in range(columns): | |
self.make_entry(row+1, column+1, width, '', True) | |
def make_entry(self, row, column, width, text, state): | |
e = tk.Entry(self, width=width) | |
if text: e.insert(0, text) | |
e['state'] = tk.NORMAL if state else tk.DISABLED | |
e.coords = (row-1, column-1) | |
e.grid(row=row, column=column) | |
ex = Excel(app, rows=5, columns=10, width=8) | |
ex.pack(padx=20, pady=20) | |
ex2 = Excel(app, rows=3, columns=5, width=20) | |
ex2.pack(padx=20, pady=20) | |
def show_cells(): | |
print('\n--== dumping cells ==--') | |
for e in ex.children: | |
v = ex.children[e] | |
print(f'{v.get()}', end=', ') | |
print() | |
bt = tk.Button(app, text='Dump', command=show_cells) | |
bt.pack(pady=20) | |
app.mainloop() |
Free to use for commercial use?
Yes, it is
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Free to use for commercial use?