From 51694a6b65968d36b2550ded367bfa3f77945009 Mon Sep 17 00:00:00 2001 From: John Strunk Date: Fri, 22 Nov 2024 20:45:40 -0500 Subject: [PATCH] Make FontFamilyDropdown compatible w/ Python 3.13 Signed-off-by: John Strunk --- ttkwidgets/font/familydropdown.py | 12 ++++++++++-- ttkwidgets/font/familylistbox.py | 4 +++- ttkwidgets/font/sizedropdown.py | 3 ++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ttkwidgets/font/familydropdown.py b/ttkwidgets/font/familydropdown.py index d4fadcbd..9a7ec11c 100644 --- a/ttkwidgets/font/familydropdown.py +++ b/ttkwidgets/font/familydropdown.py @@ -3,9 +3,11 @@ License: GNU GPLv3 Source: This repository """ + # Based on an idea by Nelson Brochado (https://www.github.com/nbro/tkinter-kit) import tkinter as tk from tkinter import font + from ttkwidgets.autocomplete import AutocompleteCombobox @@ -28,7 +30,13 @@ def __init__(self, master=None, callback=None, **kwargs): self._fonts = font_families self._font = tk.StringVar(master) self.__callback = callback - AutocompleteCombobox.__init__(self, master, textvariable=self._font, completevalues=font_families, **kwargs) + AutocompleteCombobox.__init__( + self, + master, + textvariable=self._font, + completevalues=font_families, + **kwargs, + ) self.bind("<>", self._on_select) self.bind("", self._on_select) @@ -49,7 +57,7 @@ def selection(self): :return: None if no font is selected and font family name if one is selected. :rtype: None or str """ - if self._font.get() is "" or self._font.get() not in self._fonts: + if self._font.get() == "" or self._font.get() not in self._fonts: return None else: return self._font.get() diff --git a/ttkwidgets/font/familylistbox.py b/ttkwidgets/font/familylistbox.py index ea50e46a..2d099725 100644 --- a/ttkwidgets/font/familylistbox.py +++ b/ttkwidgets/font/familylistbox.py @@ -3,9 +3,11 @@ License: GNU GPLv3 Source: This repository """ + # Based on an idea by Nelson Brochado (https://www.github.com/nbro/tkinter-kit) import tkinter as tk from tkinter import font + from ttkwidgets import ScrolledListbox @@ -54,6 +56,6 @@ def selection(self): :rtype: None or str """ selection = self.listbox.curselection() - if len(selection) is 0: + if not len(selection): return None return self.font_indexes[self.listbox.curselection()[0]] diff --git a/ttkwidgets/font/sizedropdown.py b/ttkwidgets/font/sizedropdown.py index 4ab9be87..90d010d8 100644 --- a/ttkwidgets/font/sizedropdown.py +++ b/ttkwidgets/font/sizedropdown.py @@ -3,6 +3,7 @@ License: GNU GPLv3 Source: This repository """ + # Based on an idea by Nelson Brochado (https://www.github.com/nbro/tkinter-kit) from ttkwidgets.autocomplete import AutocompleteCombobox @@ -45,7 +46,7 @@ def selection(self): :return: None if no value is selected and size if selected. :rtype: None or int """ - if self.get() is "": + if self.get() == "": return None else: return int(self.get())