Dieses Projekt dient der digitalen Umwandlung von Bildern in simulierte Darstellung aus Sicht eines rot-grün-blinden Menschen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Scrollbar.py 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import tkinter as tk
  2. from tkinter import filedialog, messagebox
  3. class AutoScrollbar(tk.Scrollbar):
  4. # A scrollbar that hides itself if it's not needed.
  5. # Only works if you use the grid geometry manager!
  6. def set(self, lo, hi):
  7. if float(lo) <= 0.0 and float(hi) >= 1.0:
  8. # grid_remove is currently missing from Tkinter!
  9. self.tk.call("grid", "remove", self)
  10. else:
  11. self.grid()
  12. tk.Scrollbar.set(self, lo, hi)
  13. def pack(self, **kw):
  14. raise TclError("cannot use pack with this widget")
  15. def place(self, **kw):
  16. raise TclError("cannot use place with this widget")
  17. class ScrollFrame:
  18. def __init__(self, master):
  19. self.vscrollbar = AutoScrollbar(master)
  20. self.vscrollbar.grid(row=0, column=1, sticky='ns')
  21. self.hscrollbar = AutoScrollbar(master, orient='horizontal')
  22. self.hscrollbar.grid(row=1, column=0, sticky='ew')
  23. self.canvas = tk.Canvas(master, yscrollcommand=self.vscrollbar.set,
  24. xscrollcommand=self.hscrollbar.set)
  25. self.canvas.grid(row=0, column=0, sticky='nsew')
  26. self.vscrollbar.config(command=self.canvas.yview)
  27. self.hscrollbar.config(command=self.canvas.xview)
  28. # make the canvas expandable
  29. master.grid_rowconfigure(0, weight=1)
  30. master.grid_columnconfigure(0, weight=1)
  31. # create frame inside canvas
  32. self.frame = tk.Frame(self.canvas)
  33. self.frame.rowconfigure(1, weight=1)
  34. self.frame.columnconfigure(1, weight=1)
  35. # update the frame
  36. self.frame.bind("<Configure>", self.reset_scrollregion)
  37. def reset_scrollregion(self, event):
  38. self.canvas.configure(scrollregion=self.canvas.bbox('all'))
  39. def update(self):
  40. self.canvas.create_window(0, 0, anchor='nw', window=self.frame)
  41. self.frame.update_idletasks()
  42. self.canvas.config(scrollregion=self.canvas.bbox("all"))
  43. if self.frame.winfo_reqwidth() != self.canvas.winfo_width():
  44. # update the canvas's width to fit the inner frame
  45. self.canvas.config(width = self.frame.winfo_reqwidth())
  46. if self.frame.winfo_reqheight() != self.canvas.winfo_height():
  47. # update the canvas's width to fit the inner frame
  48. self.canvas.config(height = self.frame.winfo_reqheight())