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.
Related
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.
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.
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
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.
I am developing using Python Tools for Visual Studio in Visual Studio 2013 community edition on Windows 8.1. My problem is that I am unable to get a Tkinter window to start. I have tried using this code:
from tkinter import *
Tk()
When I launch this code from IDLE and such, I am able to get a tkinter window, as shown:
However, when I start this in Visual Studio, no Tkinter window appears, only the console window. No error is thrown. Example:
How do I get the Tkinter window to appear when I launch the program in Visual Studio with Python tools?
Edit: Also, when I try to do this from the Python interactive window in VS, this is what I get, with no window appearing:
>>> from tkinter import *
>>> Tk()
<tkinter.Tk object at 0x02D81FD0>
Most likely the problem is that you aren't starting the event loop. Without the event loop the program will exit immediately. Try altering your program to look like this:
import tkinter as tk
root = tk.Tk()
root.mainloop()
The reason you don't need to call mainloop in IDLE is because IDLE does that for you. In all other cases you must call mainloop.