Threading improvements
This commit is contained in:
parent
6b0396a4b0
commit
40ff55f700
3 changed files with 74 additions and 58 deletions
28
textmenu.py
28
textmenu.py
|
|
@ -291,26 +291,12 @@ class TextMenu:
|
|||
# Run the GUI event loop
|
||||
self.root.mainloop()
|
||||
|
||||
# Clean up - only destroy if root still exists
|
||||
if self.root and str(self.root) != '.':
|
||||
try:
|
||||
# Clean up - destroy the window immediately to prevent hanging
|
||||
try:
|
||||
if self.root and str(self.root) != '.':
|
||||
self.root.destroy()
|
||||
except tk.TclError:
|
||||
# Window may already be destroyed
|
||||
pass
|
||||
except tk.TclError:
|
||||
# Window may already be destroyed
|
||||
pass
|
||||
|
||||
return self.selected
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Example usage
|
||||
choices = [
|
||||
"Option 1\nDescription for option 1",
|
||||
"Option 2\nDescription for option 2",
|
||||
"Option 3\nDescription for option 3",
|
||||
"Option 4\nDescription for option 4"
|
||||
]
|
||||
|
||||
menu = TextMenu(choices, title="Test Menu", timeout=10)
|
||||
result = menu.show()
|
||||
print(f"Selected: {result}")
|
||||
return self.selected
|
||||
Loading…
Add table
Add a link
Reference in a new issue