Sie sind nicht angemeldet.

1

25.10.2020, 18:04

NameError: name 'tk' is not defined[

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import tkinter as tk
from tkinter import *
counter = 0 
def counter_label(label):
  def count():
    global counter
    counter += 1
    label.config(text=str(counter))
    label.after(1000, count)
  count()
 
 
root = tk.Tk()
root.title("Counting Seconds")
label = tk.Label(root, fg="green")
label.pack()
counter_label(label)
button = tk.Button(root, text='Stop', width=25, command=root.destroy)
button.pack()
root.mainloop()


Quellcode

1
2
3
4
5
6
7
8
michi@sysvorOrt ~/python $ python uebung1.py 
Traceback (most recent call last):
  File "uebung1.py", line 1, in <module>
    import tkinter as tk
  File "/home/michi/python/tkinter.py", line 3, in <module>
    tkFenster = tk()
NameError: name 'tk' is not defined
michi@sysvorOrt ~/python $


Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/etc/portage/make.conf
# These settings were set by the catalyst build script that automatically
# built this stage.
# Please consult /usr/share/portage/config/make.conf.example for a more
# detailed example.
COMMON_FLAGS="-O2 -pipe"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"

# NOTE: This stage was built with the bindist Use flag enabled
PORTDIR="/var/db/repos/gentoo"
DISTDIR="/var/cache/distfiles"
PKGDIR="/var/cache/binpkgs"

# This sets the language of build output to English.
# Please keep this setting intact when reporting bugs.
LC_MESSAGES=C
USE="X,tcltk, alsa, cups, -kde, -python2, -gnome, gtk, -qt5, -games, elogind, tk, tkinter"
LINGUAS="DE_de"
L10N="de"
GENTOO_MIRRORS="https://mirror.eu.oneandone.net/linux/distributions/gentoo/gento/etc/portage/make.conf lines 1-22/23 82%


Quellcode

1
2
3
4
5
michi@sysvorOrt ~/python $ python
Python 3.8.5 (default, Oct 19 2020, 20:18:09) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>


Warum will er nicht?

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »michi-monster« (26.10.2020, 19:21) aus folgendem Grund: Der Fehler wurde gefunden: es lag daran das die Python Datei nicht im Arbeitsverzeichnis von Python gespeichert war.


2

26.10.2020, 19:22

Der Fehler wurde gefunden: es lag daran das die Python Datei nicht im Arbeitsverzeichnis von Python gespeichert war.


Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
sysvorOrt / # python
Python 3.8.5 (default, Oct 26 2020, 17:00:05) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.getcwd()
'/'
>>> os.chdir ("/home/michi/python")
>>> os.getcwd()
'/home/michi/python'
>>> 
KeyboardInterrupt
>>> exit()