Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to correctly import tkinter module on Spyder? Python 3.9.6 related

I want to create a python executable file with tkinter module, so far this is the code I have typed:

import tkinter as Tk
from tkinter import geometry, title, BooleanVar, set, Button
from tkinter import filedialog

import subprocess

root = Tk()
root.geometry('500x400')
root.title("Bulk upload to OpenSea")

I know that tkinter module doesn’t come by default on Spyder environment, so before compiling the program above, I watched this video , then installed miniconda, and then did all the necesary steps explained in that video to allow importing the tkinter module, I also changed the default environment to C:\Users\ResetStoreX\miniconda3\envs\spyder-env\python.exe which is the PATH in which I installed the tkinter module with anaconda prompt.

Unfortunately, after compiling the program above with the necessary steps done, I get the following error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Traceback (most recent call last):

File "C:\Users\ResetStoreX\bulk masive\untitled0.py", line 9, in
from tkinter import geometry, title, BooleanVar, set, Button

ImportError: cannot import name ‘geometry’ from ‘tkinter’
(C:\Users\ResetStoreX\miniconda3\envs\spyder-env\lib\tkinter_init_.py)

May I know what I’m doing wrong?

>Solution :

geometry and title is a method of tkinter window and toplevels, it is neither a class nor a file you can import. And set is part of python builtins. You prolly need just one type of tkinter import:

import tkinter as tk # OR from tkinter import *
from tkinter import filedialog
import subprocess

root = tk.Tk()
root.geometry('500x400')
root.title("Bulk upload to OpenSea")

Now if you want classes, like BooleanVar or Button, you’d say tk.BooleanVar and so on… Or if you want files from tkinter package, you’d say from tkinter import filedialog and so on…

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading