TTK theme not working, just old-fashioned tkinter - python

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.

Related

Tkinter buttons are completely white Mac

I'm creating a simple UI, my problem is that buttons are always white also if I change all their color properties...I'm new in Tkinter maybe I'm missing something.
This is the code, you can just copy and run:
import tkinter
tk = tkinter.Tk()
def browseFiles():
print("Browsing...")
browseButton = tkinter.Button(
tk, text="Browse files", command=browseFiles, fg='#03045e', bg='#caf0f8', background='#ef233c', activeforeground='blue').pack()
tk.mainloop()
This is a picture of result:
MacOS version : 11.5.2 withPython 3.10.0rc2, tcl-tk 8.6.11_1 and when I run the code this is the warning :
DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning.
Maybe I should downgrade to a python stable version ?
Solved :
pip3 install tkmacosx
This will install some extensions that will fix the problem.
Just one thing be sure to switch interpreter, maybe you're not using the right one.
In my case it worked when I used this one .
Check where tkmacosx has been installed, you should use the same interpreter version I guess.

Tkinter install not working after pip install tk

I need Tkinter to use in one of my projects as a button etc.
i pip installed Tkinter with the code below as i followed a tutorial online and it said to
pip install tk
is this not correct as when I import Tkinter import Tkinter. it says module not found?
I have tried to restart my project and have tried every possible pip install combination ever.
Please help explain Tia.
If you are using Python 3, Tkinter is built in. But you have to use a lowercase letter. Don't use "Tkinter", use "tkinter" instead.
Also, don't use "import tkinter", use "from tkinter import *", to import everything.
Example:
from tkinter import *
def command():
print("Hello, world!")
root = Tk()
root.title("tkWindow")
btn = Button(root, text="Click Me!", command=command)
btn.pack()
root.mainloop()
Also, remember that when you import everything from Tkinter (using from tkinter import *), you don't use tk.Tk() or tk.Button(), you just have to use Tk() and Button().
This should work for you. Good luck, and happy coding!
For me, it depended on what version of python I was using. When I was trying to do turtle graphics for the first time, my Tkinter module wasn't importing. After from tkinter import Tk, it worked. When we moved to python 3.8.5, it clearly had tkinter built into python 3 already, so try pip installing (just in case), then try from tkinter import Tk again. If it isnt working, check to make sure that you're on the latest version of python!

How do I fix Tkinter in Python-3.7?

I've tried to create a window with Tkinter but it does not work...
I am using MacOS with Python 3.7.3 in VSCode.
Maybe you can help me by this:
from tkinter import *
root = tk.Tk()
root.mainloop()
I tried many of these code versions but every time I run any of these programms he tells me:
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
I'd really like to use Tkinter but I don't now what to do...
I hope you can help me!
Thank's
I recommend re installation of python from official site.

Why does it say that no module named tkinter?

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 *

pyplot.show() reopens old tkinter dialog

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

Categories