I'm trying to set the Activity (not sure of the proper term, see screenshot) name for a Tkinter app. I'm not a Linux expert, novice, or really even beginner, but the system about dialog lists my test machine as Fedora 30. Window Manager is Gnome.
Code can't get much simpler:
import tkinter as tk
master=tk.Tk()
master.title("My lil' Application")
master.mainloop()
This is most likely either a very simple or impossible thing to accomplish. I've not been able to come up with the magical search terms that result in an answer yet. This seems like something that someone else must have run into though which means the answer has to be out there.
Thank you for your time.
Solution from stovfl:
import tkinter as tk
master=tk.Tk(className="My lil' Application")
master.title("My lil' Application")
master.mainloop()
Related
I'm making a simple GUI Application using Tkinter(Python). And I want it to minimize to System Tray and keep running. Is there any way to do so?
Based on this answer, you can use root.withdraw() method or packages like pystray.
The entire solution consists of two parts:
Hide/restore tkinter window
Create/delete systray object
1:
#import stuff...
root = tk.Tk()
root.withdraw() #hide
root.deiconify() #show again
Also remember to use mainloop()
2:
You can use packages like pystray,...
I don't know much about pystray or whatever like that, but you can follow its documentation and try its examples.
Here's a snippet of my test code
from tkinter import *
master=Tk()
master.geometry('640x340')
Button(master,text='check').pack()
def new():
print('done')
from pywinauto import Desktop, Application
master.after(1000,new)
master.mainloop()
In exactly one second the tkinter window which is created reduces in size, same thing happens for the button as well. This is just test code which I wrote after tracking down this problem in the application I am trying to build. Could somebody tell me why the window changes in size, and what I can do to prevent this?
I have checked all I could, the official documentation only mentions Tkinter once and that is referring to pywinauto’s backend, and I don't think it is relevant. Here on page 5.
I'm creating a UI with python 3.7 with tkinter. I have a button that should open a dialog and ask for a string input, in windows it works entirely as expected but for some reason it won't work on any of 3 Macs I've tried. On the Macs the main window goes gray on top and you can't interact with it, so it's as if a dialog window has opened, but the dialog window is nowhere to be found. Python is not crashing or giving any error messages either. It's baffling to me that I have not been able to find any similar problems searching online.
The button calls this method:
def add_goal(self):
newgoal = simpledialog.askstring("Input", "What goal would you like to begin tracking?", parent=self.root)
self.goal_list.goals.append(goal.Goal(newgoal,0,0))
self.set_listbox()
print(self.goal_list)
I have tested the button with only a print statement so I know the button works.
I have also tested the button with only the simpledialog line so I know the other parts aren't causing a problem. I have also tried simpledialog.askinteger just to see and that didn't work either.
If relevant I'm doing from tkinter import simpledialog at the top.
And again this all works perfectly fine on windows.
Thanks for any help, I can post the entire code if anyone wants but I don't think any of it is relevant.
Was using root.attributes("-topmost", True), the code was derived from a program that was meant to be at the front of the screen at all times which is why that line was there to begin with, but I realized it was no longer necessary and it seems to be the source of the problem.
I am trying to follow along in the book Python Programming for Kids. I am working with a group of neighborhood kids and to reduce the cost we are using the Raspberry Pi as our computer. I am a Windows guy and the GUI builder of choice for me is WxPython. I am trying to get ready for next weeks class and have run into a problem. I have entered the code below
from tkinter import *
tk = Tk()
btn = Button(tk,text = 'click me')
btn.pack()
according to the book the second line is supposed to create a window (frame I think in the Wx world) and the third line defines a button object and the fourth inserts it in the window.
However, this is not working - the tk window is not displayed nor is there a button on the screen and I have not been able to figure out why. tkinter is imported and the tk object has lots of methods/properties visible when I type dir(tk) so I know that we have tkinter on the Pi's.
Again, after entering this code nothing visible happens. I deleted the code relating to creating the button and still nothing happens so I am not sure where to start diagnosing the issue I have Googled for information and found nothing useful
Any insight would be appreciated.
I did ask this question on superuser but there is no Tkinter tag so . . .
humm do I need a
tk.pack()
statement - I will report back.
No, you do not need tk.pack(). What you do need is start the event loop. The event loop, as it's name suggests, is a loop that processes events. Everything in Tkinter happens as a response an event, including the actual drawing of a widget or window on the screen.
As the last line in your file, add the following:
tk.mainloop()
I encourage you to not do the import the way you are doing. I know a lot of tkinter tutorials do it that way, but it's a bad thing to do. Instead, do it like this:
import tkinter as tk
root = tk.Tk()
btn = tk.Button(root, text='click me')
btn.pack()
root.mainloop()
It requires typing three extra characters for every widget, but in exchange you get code that is easier to maintain over time.
PEP8 is the official python style guide, and it explicitly recommends against wildcard imports:
Wildcard imports (from import *) should be avoided, as they
make it unclear which names are present in the namespace, confusing
both readers and many automated tools. There is one defensible use
case for a wildcard import, which is to republish an internal
interface as part of a public API (for example, overwriting a pure
Python implementation of an interface with the definitions from an
optional accelerator module and exactly which definitions will be
overwritten isn't known in advance).
See http://legacy.python.org/dev/peps/pep-0008/#imports
I created a minimal Tkinter GUI as follows:
import Tkinter
root = Tkinter.Tk()
root.mainloop()
Everything is fine if I run the above code on RHEL5, except that the maximize button does not work properly(resizing is available). If I click the button, the window does not expand to occupy the whole screen. And I belive this issue is platform-specific, because there is no such issue for the same code on Windows.
Does anyone know the reason for this? Is there any solution? Thanks!
It works for me in Fluxbox. Try putting something in root like a label so it has something to display. Probably won't make any difference but worth a try.