Reputation: 65
I'm trying to use Tkinter with Python in Visual Studio Code and its working fine except I get this yellow underline here:
and when I hover on it it shows a lot of stuff here:
Upvotes: 1
Views: 731
Reputation: 8421
It's the design logic of pylint
. If you want to solve it, you can take these methods:
You can switch to another linter, such as mypy
,pylama
,flake8
and so on. But you will still encounter the warning of unable to detect undefined names
.
Explicit the thing you want to import, such as: from tkinter import Tk, Label
. This is recommended.
Add this in the settings.json file:
"python.linting.pylintArgs": [ "--disable=all --enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode,unused-wildcard-import,wildcard-import" ],
The beginning of the settings was the default setting of pylint
in
the VSCode, unused-wildcard-import,wildcard-import
was set to
remove warning of wildcard.
Upvotes: 1
Reputation: 11
In python there are different ways to import packages.
In your example you use the first variant with a so-called wildcard. This means you’ll put all the names from the tkinter package into your global namespace. It would be better and is common to import tkinter with import tkinter as tk
in order to maintain a certain encapsulation.
You then address objects from tkinter with tk.object_name.
Upvotes: 1