Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter
#1
I watched a video on tkinter and in the video this code was written:


#!/usr/bin/python3
from tkinter import
root = Tk()

thelable = lable(root, text="this is too easy")
thelable.pack()
root.mainloop()
but my computer gave me this output:
Error:
'/home/linuxgamer21/Schreibtisch/tkinter.py' File "/home/linuxgamer21/Schreibtisch/tkinter.py", line 2 from tkinter import ^ SyntaxError: invalid syntax
what did I do wrong?
Reply
#2
I'm not familiar with Tkinter really, but my guess is that you probably copied the code wrong out of the video, or maybe the video was wrong somehow. It looks like you want
from tkinter import Tk
(you truncated the end of the line)
Reply
#3
this is also not working
Reply
#4
import tkinter as tk

root = tk.Tk()
 
thelabel = tk.Label(root, text="this is too easy")
thelabel.pack()
root.mainloop()
Reply
#5
Traceback (most recent call last):
File "/home/linuxgamer21/Schreibtisch/tkinter.py", line 2, in <module>
import tkinter as tk
File "/home/linuxgamer21/Schreibtisch/tkinter.py", line 4, in <module>
root = tk.Tk()
AttributeError: module 'tkinter' has no attribute 'Tk'
Reply
#6
Rename your file - Python is importing from your file instead of the module you intended.

You generally don't want to name your file anything that you can import in a Python shell, e.g. test, os, sys, etc.
Reply
#7
'/home/linuxgamer21/Schreibtisch/animationentest.py'
Traceback (most recent call last):
File "/home/linuxgamer21/Schreibtisch/animationentest.py", line 2, in <module>
import tkinter as tk
ModuleNotFoundError: No module named 'tkinter'
Reply
#8
How are you running your scripts? I realize you have a Python 3 shebang, but it looks like you're actually using Python 2 when the code is supposed to be Python 3.
Reply
#9
#!/usr/bin/python3
import tkinter as tk

root = tk.Tk()

thelabel = tk.Label(root, text="this is too easy")
thelabel.pack()
root.mainloop()
Reply
#10
some linux versions don't install tkinter by default (OpenSuse for one)
in this case, import using Yast or YUM or zypper or whatever the install package is named on your distro.
as a simple test:
  • open a terminal window
  • type 'python' you should see interactive prompt >>>
  • if python 3: type import tkinter
  • else if python 2.7 type import Tkinter
  • If no errors, tkinter is installed
  • exit interpreter by typing quit()
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020