![]() |
tkinter - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: tkinter (/thread-14087.html) Pages:
1
2
|
tkinter - peer - Nov-14-2018 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: what did I do wrong?
RE: tkinter - micseydel - Nov-14-2018 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) RE: tkinter - peer - Nov-14-2018 this is also not working RE: tkinter - Larz60+ - Nov-14-2018 import tkinter as tk root = tk.Tk() thelabel = tk.Label(root, text="this is too easy") thelabel.pack() root.mainloop() RE: tkinter - peer - Nov-14-2018 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' RE: tkinter - micseydel - Nov-14-2018 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. RE: tkinter - peer - Nov-14-2018 '/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' RE: tkinter - micseydel - Nov-14-2018 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. RE: tkinter - peer - Nov-14-2018 #!/usr/bin/python3 import tkinter as tk root = tk.Tk() thelabel = tk.Label(root, text="this is too easy") thelabel.pack() root.mainloop() RE: tkinter - Larz60+ - Nov-14-2018 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:
|