MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / SheetGUI

Class SheetGUI

tools/python-3.11.9-amd64/Tools/demo/spreadsheet.py:475–794  ·  view source on GitHub ↗

Beginnings of a GUI for a spreadsheet. TO DO: - clear multiple cells - Insert, clear, remove rows or columns - Show new contents while typing - Scroll bars - Grow grid when window is grown - Proper menus - Undo, redo - Cut, copy and paste - Formatt

Source from the content-addressed store, hash-verified

473import tkinter as Tk
474
475class SheetGUI:
476
477 """Beginnings of a GUI for a spreadsheet.
478
479 TO DO:
480 - clear multiple cells
481 - Insert, clear, remove rows or columns
482 - Show new contents while typing
483 - Scroll bars
484 - Grow grid when window is grown
485 - Proper menus
486 - Undo, redo
487 - Cut, copy and paste
488 - Formatting and alignment
489 """
490
491 def __init__(self, filename="sheet1.xml", rows=10, columns=5):
492 """Constructor.
493
494 Load the sheet from the filename argument.
495 Set up the Tk widget tree.
496 """
497 # Create and load the sheet
498 self.filename = filename
499 self.sheet = Sheet()
500 if os.path.isfile(filename):
501 self.sheet.load(filename)
502 # Calculate the needed grid size
503 maxx, maxy = self.sheet.getsize()
504 rows = max(rows, maxy)
505 columns = max(columns, maxx)
506 # Create the widgets
507 self.root = Tk.Tk()
508 self.root.wm_title("Spreadsheet: %s" % self.filename)
509 self.beacon = Tk.Label(self.root, text="A1",
510 font=('helvetica', 16, 'bold'))
511 self.entry = Tk.Entry(self.root)
512 self.savebutton = Tk.Button(self.root, text="Save",
513 command=self.save)
514 self.cellgrid = Tk.Frame(self.root)
515 # Configure the widget lay-out
516 self.cellgrid.pack(side="bottom", expand=1, fill="both")
517 self.beacon.pack(side="left")
518 self.savebutton.pack(side="right")
519 self.entry.pack(side="left", expand=1, fill="x")
520 # Bind some events
521 self.entry.bind("<Return>", self.return_event)
522 self.entry.bind("<Shift-Return>", self.shift_return_event)
523 self.entry.bind("<Tab>", self.tab_event)
524 self.entry.bind("<Shift-Tab>", self.shift_tab_event)
525 self.entry.bind("<Delete>", self.delete_event)
526 self.entry.bind("<Escape>", self.escape_event)
527 # Now create the cell grid
528 self.makegrid(rows, columns)
529 # Select the top-left cell
530 self.currentxy = None
531 self.cornerxy = None
532 self.setcurrent(1, 1)

Callers 1

test_guiFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_guiFunction · 0.68