I'm new to Python.
I'm writing the code based on a reference book,
The following error message has occurred.
I don't know how to deal with it, so I would appreciate it if you could ask.
Corresponding source code
Traceback (most recent call last): File "C: /Users/ken/Desktop/de01.py", line 21, in<module> root.geometry ("200x150") File "C: \ Program Files \ WindowsApps \ PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0 \ lib \ tkinter \ __ init__.py", line 2035, in wm_geometry return self.tk.call ('wm','geometry', self._w, newGeometry) AttributeError:'str' object has no attribute'tk'
Supplementary information (FW/tool version, etc.)
import tkinter as tk import tkinter.filedialog as fd import PIL.Image import PIL.ImageTk def dispPhoto (path): #Load image newImage = PTL.Image.open (path) .resize ((300,300)) #Display the image on the label imageData = PIL.ImageTK.PhotoImage (newImege) imageLabel.configure (image = imageData) imageLabel.image = imageData def openFile (): fpath = fd.askopenfilename () if fpath: dispPhoto (fpath) root = tk.TK root.geometry ("200x150") btn = tk.Button (text = "open file", command = openFile) imageLabel = tk.Label () btn.pack () imageLabel.pack () tkmainloop ()
Answer # 1
For the time being
*** 17,27 **** if fpath: dispPhoto (fpath) ! root = tk.TK root.geometry ("200x150") btn = tk.Button (text = "open file", command = openFile) imageLabel = tk.Label () btn.pack () imageLabel.pack () ! tkmainloop () --- 17,27 ---- if fpath: dispPhoto (fpath) ! root = tk.Tk () root.geometry ("200x150") btn = tk.Button (text = "open file", command = openFile) imageLabel = tk.Label () btn.pack () imageLabel.pack () ! root.mainloop ()
Is not it
dispPhotoThere seems to be a misspelling in the function.
- python - error message cannot unpack non-iterable int object resolution
- python 3x - library cannot be installed due to ssl error in python pip
- python - categorical_crossentoropy error does not resolve
- resolve python error code
- python - tuple error does not resolve
- python - how to resolve attribute error
- python - resolve program error "keyerror: 0"
- i want to resolve a syntax error in a python while statement
- python - the py file cannot be executed in the task scheduler 0x2 error
- python - program error removal with opencv tracker
- python - an error occurs in the if statement program that compares the size of numbers
- error in import xlrd of python file from cakephp
- python - image cannot be read by opencv
- python - cannot convert csv file to excel file (contents are not copied )
- python - error in beautifulsoup4
- ios - [unity] i want to resolve the build error of unity cloud build
- python - i get an error when i try to do a simple regression analysis using sklearn
- indent error doesn't go away, python
- python - sklearn, svm error