Update tkscrolledframe.py

This commit is contained in:
B.Jothin kumar 2021-10-08 13:23:02 +05:30 committed by GitHub
parent dc3b05c546
commit 3a36996e75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,26 +3,15 @@
"""Implementation of the scrollable frame widget.""" """Implementation of the scrollable frame widget."""
import sys import sys
import tkinter as tk
try: try:
# Python 3 # Python 3
import tkinter as tk import tkinter.ttk as ttk
except (ImportError): except ImportError:
# Python 2
import Tkinter as tk
try:
try:
# Python 3
import tkinter.ttk as ttk
except (ImportError):
# Python 2
import ttk
except (ImportError):
# Can't provide ttk's Scrollbar # Can't provide ttk's Scrollbar
pass pass
__all__ = ["ScrolledFrame"] __all__ = ["ScrolledFrame"]
@ -68,7 +57,7 @@ class ScrolledFrame(tk.Frame):
if not scrollbars: if not scrollbars:
scrollbars = self._DEFAULT_SCROLLBARS scrollbars = self._DEFAULT_SCROLLBARS
elif not scrollbars in self._VALID_SCROLLBARS: elif scrollbars not in self._VALID_SCROLLBARS:
raise ValueError("scrollbars parameter must be one of " raise ValueError("scrollbars parameter must be one of "
"'vertical', 'horizontal', 'both', or " "'vertical', 'horizontal', 'both', or "
"'neither'") "'neither'")
@ -78,17 +67,17 @@ class ScrolledFrame(tk.Frame):
# Whether to use ttk widgets if available # Whether to use ttk widgets if available
if "use_ttk" in kw: if "use_ttk" in kw:
if ttk and kw["use_ttk"]: if ttk and kw["use_ttk"]:
Scrollbar = ttk.Scrollbar scrollbar = ttk.Scrollbar
else: else:
Scrollbar = tk.Scrollbar scrollbar = tk.Scrollbar
del kw["use_ttk"] del kw["use_ttk"]
else: else:
Scrollbar = tk.Scrollbar scrollbar = tk.Scrollbar
# Default to a 1px sunken border # Default to a 1px sunken border
if not "borderwidth" in kw: if "borderwidth" not in kw:
kw["borderwidth"] = 1 kw["borderwidth"] = 1
if not "relief" in kw: if "relief" not in kw:
kw["relief"] = "sunken" kw["relief"] = "sunken"
# Set up the grid # Set up the grid
@ -109,10 +98,10 @@ class ScrolledFrame(tk.Frame):
c.bind("<Configure>", self._resize_interior) c.bind("<Configure>", self._resize_interior)
# Scrollbars # Scrollbars
xs = self._x_scrollbar = Scrollbar(self, xs = self._x_scrollbar = scrollbar(self,
orient="horizontal", orient="horizontal",
command=c.xview) command=c.xview)
ys = self._y_scrollbar = Scrollbar(self, ys = self._y_scrollbar = scrollbar(self,
orient="vertical", orient="vertical",
command=c.yview) command=c.yview)
c.configure(xscrollcommand=xs.set, yscrollcommand=ys.set) c.configure(xscrollcommand=xs.set, yscrollcommand=ys.set)