I'm trying to import ThemedTK from ttkthemes in Python3 but am getting the following error message:
line 4, in
from ttkthemes import Themed_TK
ImportError: cannot import name 'Themed_TK' from 'ttkthemes'
Any ideas?
from tkinter import filedialog
from tkinter import ttk
from ttkthemes import ThemedTK
from reportlab.lib.units import mm
from draw import bellGen
root = ThemedTK()
Apparently it's ThemedTk. With lowercase "k".
Here's the documentation for it: ttkthemes.readthedocs.io/en/latest/example.html
Related
I'm trying to make an interface using tkxui and tkinter for the modules it doesn't cover (Label, anchors etc)
from urllib.request import urlopen
from PIL import Image, ImageTk
from io import BytesIO
from tkinter import *
import tkxui
win = tkxui.Tk(display=tkxui.FRAMELESS, defaultBorder=True)
win.geometry("700x400")
win.title("Window Title")
win.minsize(700, 400)
win.center()
URL = "http://www.universeofsymbolism.com/images/ram-spirit-animal.jpg"
u = urlopen(URL)
raw_data = u.read()
u.close()
im = Image.open(BytesIO(raw_data))
photo = ImageTk.PhotoImage(im)
When running this code I get AttributeError: type object 'Image' has no attribute 'open'(line 18) as Traceback. It seems like tkinter and PIL are overlapping with the open function.
How can I avoid this?
Solved by importing the needed tkinter modules like this:
from tkinter.constants import *
and
from tkinter import Label
Im using PIL and TKinter to open an image. I do not understand why I'm getting this error
import os
import random
from PIL import Image
import time
from tkinter import *
root = Tk()
def timer(mins):
time.sleep(mins * 60)
def anmuViewer():
random_pic = (random.choice(os.listdir("D:/de_clutter/memez/anmu")))
openPic = Image.open('D:/de_clutter/memez/anmu/' + random_pic)
openPic.show()
timer(3)
start_btn = Button(root, text = "Start", command = anmuViewer)
start_btn.pack()
root.mainloop()
what should happen is a tkinter window should pop up with only a button called "start". When I click that button, a new window with the image should pop up. instead I get this error
line 17, in anmuViewer
openPic = Image.open('D:/de_clutter/memez/anmu/' + random_pic)
AttributeError: type object 'Image' has no attribute 'open'
Like Michael Butscher said,
"tkinter.Image" overwrites "PIL.Image" in your module's namespace. Avoid imports with *
But if you must use a wildcard import, importing tkinter before PIL should solve your problem
from tkinter import *
import os
import random
from PIL import Image
import time
from tkinter import *
from tkinter import messagebox
root = Tk()
messagebox.showinfo("Hello world", "you are the best")
root.mainloop()
Why do I have to have to import messagebox explicitly when I am import all using *
messagebox is a submodule of the tkinter package.
The wildcard import syntax doesn't import submodules, only the names that are defined in the tkinter package itself.
Therefore you need to import the messagebox submodule explicitly.
References
https://docs.python.org/3/library/tkinter.html#tkinter-modules
https://docs.python.org/3/reference/simple_stmts.html#the-import-statement
Relevant tkinter sources
https://github.com/python/cpython/blob/3.6/Lib/tkinter/__init__.py
https://github.com/python/cpython/blob/3.6/Lib/tkinter/messagebox.py
import os.path
from tkinter import *
from tkinter.ttk import *
import tkinter.filedialog
import tkinter.font as Font
try:
from tkinter.ttk import Button, Scrollbar
except ImportError:
pass
class Edit_save(object):
def __init__(self):
self.root=Tk()
self.root.title('EditSave')
self.root.geometry('+120+50')
self.font_en = Font(self.root, size=12)
self.font_text = Font(self.root,family="Helvetica",size=12,weight='normal')
self.menubar = Menu(self.root, bg='purple')
self.filemenu = Menu(self.menubar)
My code is like that, the error message is
'module' object is not callable.
The question is self.font_en = Font(self.root, size=12), Font is not callable. How should I solve the problem?
Thanks very much! And I am using Python 3.6.1
from tkinter.font import Font
I figure out what the problem is, it should be imported this way.
I'm just beginning to learn tkinter at the moment, and when importing messagebox I found that I must not really understand import statements.
The thing that confuses me is that:
import tkinter as tk
def text_box():
if tk.messagebox.askokcancel("Quit", "Never Mind"):
root.destroy()
root = tk.Tk()
button = tk.Button(root, text="Press the button", command=text_box)
button.pack()
root.mainloop()
compiles fine, but pressing the button gives the error 'module' object has no attribute 'messagebox', while the code:
import tkinter as tk
from tkinter import messagebox
...
if messagebox.askokcancel("Quit", "Never Mind"):
...
...works without a hitch.
I get a similar error if I import with from tkinter import *.
The help for tkinter shows messagebox in the list of PACKAGE CONTENTS, but I just can't load it in the normal way.
So my question is, why...and what is it about importing that I don't understand?
Just thought I should mention—the code only works in Python 3, and in Python 2.x messagebox is called tkMessageBox and is not defined in tkinter.
tkinter.messagebox is a module, not a class.
As it isn't imported in tkinter.__init__.py, you explicitly have to import it before you can use it.
import tkinter
tkinter.messagebox # would raise an ImportError
from tkinter import messagebox
tkinter.messagebox # now it's available eiter as `messagebox` or `tkinter.messagebox`
try this
import sys
from tkinter import *
... and your code