Tkinter window not responding after destroy() - macOS - python

The goal is for the user to choose a file and then the program to process it:
from tkinter import filedialog, Tk
root = Tk()
root.withdraw()
filename = filedialog.askopenfilename()
root.destroy()
# Long running process after this...
This works fine in windows, but in mac it leaves a Python app not responding in the dock bar after root.destroy().
The program still runs in the background and process the file, but I wonder if this "Not responding" app in the dock can be removed or hidden after root.destroy().
My setup:
Python 2.7.17 and 3.7.5.
macOS Catalina 10.15.4

Related

Python 3.8.9 MacOS M1 tkinter UI not opening inside of VSCode

so I am trying to use Tkinter inside of VSCode on my M1 mac. When I use Tkinter through IDLE it works fine but once I try to open it inside of VSCode it the UI submenu just stalls. I'm using python 3.8.9 as my kernel but it won't seem to open even when I switch to any other versions. Tkinter is installed fine it is just some issue with how VSCode is running it but I have no idea how to fix it.
import tkinter as tk
window = tk.Tk()
Here I provided some screenshots of what happens
While using Idle
While using VSCode (The app just bounces up and down never opening the UI)
You have not started the event loop. IDLE does mainloop for you, otherwise, you need to call it by yourself.
import tkinter as tk
root = tk.Tk()
root.mainloop()
You can refer to here.

Python freezes upon Tkinter destroy() method

I'm trying to build simple window with buttons in Tkinter. Exit button should act with destroy() or sys.exit, but both option just lead to no response from window and only force close of Python helps. MacOs, Python 3.9
import tkinter as tk
from tkinter import ttk
import sys
class App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.attributes('-alpha',1)
self.attributes('-topmost',True)
self.overrideredirect(True)
self.resizable(False,False)
self.title('Monitor')
self.set_ui()
def set_ui(self):
exit_b=ttk.Button(self,text='Exit',command=self.app_exit)
exit_b.pack(fill=tk.X)
def app_exit(self):
self.destroy()
root=App()
root.mainloop()
Sorry for being noob, and not tested earlier, just switched to Mac from Windows. Simply running it for a test from IDE give this results, but when I export script as a python script with .py extension and running it straight with IDLE all works fine. There is definitely some problems with interaction between VS code IDE and Python interpreter for Apple silicon, cause it should not work like this, and its ridiculous to import script and execute it from IDLE every time just to test it as you write.

Tkinter window not showing in Pycharm

I can't get tkinter to work in Pycharm. There is no error message, but the window doesn't pop up. It works perfectly fine in IDLE. Even just a simple window doesn't work:
import tkinter as tk
window = tk.Tk()
window.mainloop()
The output looks like:
Process finished with exit code 0
I'm on mac os x with python 3.8 and pycharm 2020.1.2.
Some sources suggested installing the package future, but this doesn't work either.

How can I use my python program on my desktop (windows 7) to display a simple notification on my desktop without notify2, notify-send, pqt5?

I tried those 3 options and they don't work.
Notifiy-send is not a command and I don't have linux or ubuntu.
I can't import notify2 in python, because I get the error where it says that the notify2 library can't import dbus, and I tried to pip3 install dbus, but it doesn't exist (what???). I can't install homebrew to fix it.
pqt5 runs without compile errors, but no notification is showing up. It works fine in my mac, but not on my windows pc.
You can use tkinter, which is an interface for the Tk GUI toolkit.
On Python 3:
import tkinter as tk
from tkinter import messagebox
root = tk.Tk()
root.withdraw() # This hides the main window of the gui
messagebox.showinfo("Pay attention", "Something happened!")
On Python 2:
import Tkinter as tk
import tkMessageBox
root = tk.Tk()
root.withdraw() # This hides the main window of the gui
tkMessageBox.showinfo("Pay attention", "Something happened!")
This creates a simple popup alert and should work on Windows.

Tkinter opens console window with window

I am a complete newbie at Python. Meanwhile, I'm working with Tkinter to integrate a GUI into my application using Python 2.7. This is the code so far:
import Tkinter
top = Tkinter.Tk()
top.mainloop()
However, when I execute the file, a console window and the GUI pops up. How do I get rid of the console window during startup?
Rename your Python script as .pyw (not .pyc). This will tell the invoker to to instantiate a console window. Source
Note however, this will work for non-GUI based scripts too which can cause undesireqable behaviour - such as not being able to see your script.

Categories

Resources