S
S
Span4ev2022-01-28 08:38:40
Python
Span4ev, 2022-01-28 08:38:40

VS Code, Python and a bunch of bugs. Just Tk() or tk.Tk()?

Hello. I am learning python using vs code. I came across two options for calling a tkinter frame:
1.

from tkinter import * 
window = Tk()  # пример


2.
import tkinter as tk
window = tk.Tk()


If I call it like this, I get the following errors:

wildcard import tkinter



spoiler

Unused import(s) enum, sys, types, TclError, re, wantobjects, TkVersion, TclVersion, READABLE, WRITABLE, EXCEPTION, EventType, Event, NoDefaultRoot, Variable, StringVar, IntVar, DoubleVar, BooleanVar, mainloop, getint, getdouble, getboolean, Misc, CallWrapper, XView, YView, Wm, Tcl, Pack, Place, Grid, BaseWidget, Widget, Toplevel, Canvas, Checkbutton, Entry, Frame, Label, Listbox, Menu, Menubutton, Message, Radiobutton, Scale, Scrollbar, Text, OptionMenu, Image, PhotoImage, BitmapImage, image_names, image_types, Spinbox, LabelFrame, PanedWindow, NO, FALSE, OFF, YES, TRUE, ON, N, S, W, E, NW, SW, NE, SE, NS, EW, NSEW, CENTER, NONE, X, Y, BOTH, LEFT, TOP, RIGHT, BOTTOM, RAISED, SUNKEN, FLAT, RIDGE, GROOVE, SOLID, HORIZONTAL, VERTICAL, NUMERIC, CHAR, WORD, BASELINE, INSIDE, OUTSIDE, SEL, SEL_FIRST, SEL_LAST, END, INSERT, CURRENT, ANCHOR, ALL, NORMAL, DISABLED, ACTIVE, HIDDEN, CASCADE, CHECKBUTTON, COMMAND, RADIOBUTTON, SEPARATOR, SINGLE, BROWSE, MULTIPLE, EXTENDED, DOTBOX, UNDERLINE, PIESLICE, CHORD, ARC, FIRST, LAST, BUTT, PROJECTING, ROUND, BEVEL, MITER, MOVETO, SCROLL, UNITS and PAGES from wildcard import of tkinter



If you use the 2nd approach, then errors occur:
Module name "12" doesn't conform to snake_case naming style

(solution: "If you are a Visual Studio Code user and want to ignore this, you can add to /settings.json:")

wildcard import tkinter pylint

(solution: you can add to /settings.json :)

As a result, in settings.json I add this:

"python.linting.pylintArgs": [
        "--disable=C0111",
        "--disable=C0103"
    ]


Previous errors disappear, but another one appears after debugging and starting the window. Appears when I switch to another vs code window and back:

An exception occurred NameError
name 'tk' is not defined

in this line "window = tk.Tk()"

What to use to stop fixing errors and start learning python?
Tk() or tk.Tk() ?
And I correctly understood that these errors are not really terrible errors (apparently, except for "A NameError exception has occurred"), but rather warnings and they can be ignored, and all this is a consequence of the work of Pylint? But it's still somehow unpleasant when there are some problems. Maybe use something else to highlight errors? What do you advise?

As for the main question, it seems to be better to call not everything at once, and use tk.Tk(). But what about

An exception occurred NameError
name 'tk' is not defined

?
With from tkinter import * there is no such error. I end up not learning python but spending hours googling how to get rid of it, how to solve this problem, etc.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
soremix, 2022-01-28
@Span4ev

1. Yes, these are not errors, but the usual warnings that the code written somewhere does not comply with PEP8. In principle, I would disable all PEP8 warnings, they will not affect the highlighting of syntax and other errors in any way.
2. It's better not to import the contents of the module through *, in order to avoid confusion.
import tkinter as tk- normal option
3.

Appears when I switch to another vs code window and back
and before switching the tkinter window normally appears? Is there another file nearby by any chance tkinter.py? Although according to the wildcard warnings, it seems that it is not. Please attach the full code and the full error you are getting.

S
Sergey Gornostaev, 2022-01-28
@sergey-gornostaev

First, these are not errors, but linter warnings. Secondly, it is better to learn without an IDE .

K
Konstantin Nagibovich, 2022-01-28
@nki

What to use to stop fixing bugs and start learning Python?

You don't need Tk to start learning Python. Enough standard libraries.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question