Can anyone explain, why i get different results with this Code on linux and windows. On windows its a complete color picker and on Linux its Crap.
Both Tkinter Modules are Version(8.6)
from tkinter import *
from tkinter.colorchooser import *
def getColor():
color = askcolor()
print color
Button(text='Select Color', command=getColor).pack()
mainloop()
Windows Example
Linux Example
from the comments in the source code of colorchooser.py:
# this module provides an interface to the native color dialogue
# available in Tk 4.2 and newer.
You are seeing a native dialog from underlying OS, not a dialog built the usual tkinter way.
The answer to the question of why it's different on different platforms is that on both windows and the mac, the dialogs are provided by the underlying OS. On linux, tkinter must draw the dialog itself.
Related
I just upgraded Python from 3.8 to 3.10 and the Tkinter full screen attribute no longer works as it used to.
I'm using Mac OS Big Sur 11.6.6 (Macbook M1). I had Python 3.8 installed on this Macbook and it has been working fine until I upgraded Python today.
Here is the code and the root window does not show in full screen for Python 3.10:
if __name__ == '__main__':
root = tkinter.Tk()
root.attributes('-fullscreen', True)
root.mainloop()
Any help would be much appreciated because I'm stuck. I have also seen other problems with my UI in Python 3.10 so if I'm not able to solve these problems I may revert back to Python 3.8 :(
UPDATE 1 I've noticed that my Macbook makes a bleep sound when I run with the full screen attribute but it does not if I comment out that row.
I've also noticed that it makes the same bleep sound when I type on the keyboard e.g. in an Entry widget. It did not use to do that in Python 3.8, so may be related.
UPDATE 2 I am able to do a somewhat ugly workaround by using a delay and setting the full screen attribute after 250 ms with a root.after(...) function. Then it works. It does not look very nice since empty white backgrounds flash by before the actual program opens.
You need to use root.wm_attributes() instead.
Example
import tkinter as tk
root = tk.Tk()
root.wm_attributes('-fullscreen','true')
root.mainloop()
Yet another way to do this is by calling tcl as follows
root.tk.call("::tk::unsupported::MacWindowStyle", "style", root._w, "plain", "none")
use only either of the methods.
Good day.
I installed python 2 and python 3 in my laptop. And i'm using python 3 interpreter in writing my codes. Here is my code.
#! /usr/bin/python3
from tkinter import *
root = Tk()
theLabel = Label(root, text ="This is too easy")
theLabel.pack()
root.mainloop()
But when I double clicked the save file icon. It will say no module name tkinter. Can some one help me please?
python 2 and python 3 use tkinter in a different way.
Note: Tkinter has been renamed to tkinter in Python 3. The 2to3 tool will automatically adapt imports when converting your sources to Python 3.
The above lines are from python documentation. Not sure if python is loading tkinter using python 2 or python 3..May be internal PYTHONPATH is
messed up
Rather try this,
try:
import tkinter as tk
except ImportError:
import Tkinter as tk
Note: In these situations where you use multiple versions of same modules, try using virualenv
Virtual Env
you need to check the module name or package name before using it, do this
from Tkinter import *
On my computer with Win8.1 when I use following code
from tkinter import *
from tkinter.ttk import *
Tk().mainloop()
I see only the old looking tkinter. Any idea how to fix it?
I tried to use different theme with no result.
For some reason following code:
from tkinter import *
from tkinter.ttk import *
Style().theme_use("alt")
Tk().mainloop()
results with two identical tkinter old-fashioned windows which seems not to be correct.
PS: It seems to be issue related with Win8.1, see here:
Python 2.7 - ttk module seemingly not working in Windows 8.1
But I found no information how to fix it. Any news would be welcome. :)
EDIT1:
After trying following snippet:
from tkinter import *
from tkinter.ttk import *
from functools import partial
root = Tk()
style = Style(root)
def change(name, style):
style.theme_use(name)
for s in style.theme_names():
lb = Button(root, text=s, command=partial(change, s, style))
lb.pack()
I could say the themes are changing not only for color but completely. What is still puzzling me is I cannot see the nice fancy graphic which I expect to see.
I tried to change my windows settings for performance or to visual aspect but it is not the reason why it is not working.
If you have Win 8.1 do you have tkk working as expected?
EDIT2:
This is my look using example from
http://www.tkdocs.com/tutorial/firstexample.html
(Win7 and Win8.1)
The difference can be easily seen on ubuntu between the themes.
So, maybe it is a problem with win8.1. Considered using the ttkthemes module? The ttkthemes module is another set of more "Stylish" styles.
To install:
sudo apt-get install python3-tk
sudo -H pip3 install ttkthemes
To know more, go to:
https://github.com/RedFantom/ttkthemes/wiki/Usage
I have answered another similar question,you can refer to it through this link:
How to make pyinstaller import the ttk theme?
Lemme know in the comments if this also, doesn't work.
EDIT: This seems to be a problem restricted to Tcl/Tk on Mac OS systems. So if you have no experience with that, this topic might be moot...
I want to have a Python script that does two things:
Ask the user for a file name via a Tkinter file dialog.
Plot some data from said file.
The problem is, matplotlib uses Tkinter for the graphical representations, and whenever I call pyplot.show() in non-interactive mode, the (before closed) file dialog pops up again. It seems to me like pyplot.show() gathers a list of all Tkinter windows and shows them all. I did not find any help on this however. I tried for both Python 2.7 and 3.3, since a lot of the Tkinter module seems to have changed, but it's the same phenomenon. The slightly strange workaround I came up with is to go into matplotlib interactive mode and then keep the windows open with a raw_input() command.
Here is a minimal code snippet that works in Python 2 and 3 to show the problem:
import matplotlib.pyplot as plt
# import Tkinter GUI (changes from Python 2.x to 3.x)
try:
import Tkinter
except (ImportError):
import tkinter as Tkinter
try:
from tkFileDialog import askopenfilename
except (ImportError):
from tkinter.filedialog import askopenfilename
root = Tkinter.Tk()
root.withdraw()
input_filename = askopenfilename(master=root)
# This seemed promising, but it doesn't help
root.destroy()
plt.figure()
# uncommenting this to switch to interactive mode is a workaround
#plt.ion()
plt.show()
# Python 2.x and 3.x compatible wait for input:
try: input = raw_input
except NameError: pass
# Wait for keystroke (for interactive mode)
input("Press enter when done...")
I'm sorry if I'm missing something obvious here, I am not that well-versed in Python, and I did not find satisfying information on this problem. But my gutt tells me there has to be a simple and elegant solution for this.
System information (most recent versions I tried):
Python 3.3 (from MacPorts)
matplotlib 1.3.x (built from github master)
Mac OS X 10.8.3
Tcl/Tk 8.6.0 (from MacPorts)
Thanks,
Floh
I have downloaded python 2.5. I would like to know if Tkinter is included with python or is it a separate download?
Yes, it is included.
http://wiki.python.org/moin/TkInter
If you are using linux just open your terminal and type python and in the python interpreter type from Tkinter import* if it doesn't show any error messages you are good to go. You can try this to check every package of python like Pygame just replace Tkinter by Pygame