Expected type 'Canvas', got 'int' instead - python

from tkinter import *
window = Tk()
window.title('Pomodoro timer')
window.config(padx=100, pady=50)
canvas = Canvas(width=200, height=224)
tomato_img = PhotoImage(file="C:/vscode/tomato.png")
canvas.create_image(102, 112, image=tomato_img)
Canvas.create_text(102, 112, text='00:00')
canvas.pack()
window.mainloop()
This is the code that I'm working on
when I'm trying to add two integers for x and y co-ordinates to the Canvas.create_text function, it gives me this error
Traceback (most recent call last):
File "C:\pycharm and thonny\pythonProject1\main.py", line 26, in <module>
Canvas.create_text(102, 112, text='00:00')
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2810, in create_text
return self._create('text', args, kw)
AttributeError: 'int' object has no attribute '_create'

Related

_tkinter.TclError: unkown option "-bd"

I have the following two files:
main.py
import tkinter as tk
import hashlib, json
from tkml import element
f = open("users.json", "r")
users = json.loads(f.read())
f.close()
f = open("users.json", "w")
window = tk.Tk()
window.title("Hello wold")
window.geometry("600x800")
pages = {}#initialize this variable
currentPage = ""#initialize this variable
def goTo(pageName):
global pages, currentPage
pages[currentPage].unloads()
pages[pageName].load(window)
currentPage = pageName
pages = {
"SignInOrCreateAccount": element(tk.Frame(),
[
element(tk.Button(text = "sign in", command = lambda : goTo("SignIn")), [], lambda widget, parent : widget.place(parent, anchor = "NW", relx = 0, rely = 0, x = 30, y = 30)),
element(tk.Button(text = "create account", command = lambda : goTo("CreateAccount")), [], lambda widget, parent : widget.place(parent, anchor = "NE", relx = 0, rely = 0, x = 30, y = 30))
], lambda widget, parent: widget.place(parent, relx = 0, rely = 0, relwidth = 1, relheight = 1))
}
currentPage = "SignInOrCreateAccount"
pages[currentPage].loads(window)
def saveUsersChanges():
global f, users
json.dump(users, f)
def attemptSignIn(username, password):
if username in users:
if hashlib.sha256(password.encode()).hexdigest() == users[username]["password"]:
pass # left off here
def onClose():
global f
saveUsersChanges()
f.close()
window.protocol("WM_DELETE_WINDOW", onClose())
tk.mainloop()
and tkml.py
class element:
def __init__(self, widget , children, load, unload = lambda widget: widget.place_forget()):
self.widget = widget # the tk widget
self.load = load # load just this widget using lambda function
self.unload = unload
self.children = children # child widgets
def loads(self, parent): # load this widget and all child widgets
self.load(self.widget, parent)
for child in self.children:
child.loads(self)
def unloads(self): # unloads widget and all child widgets
self.unload(self.widget)
for child in self.children:
child.unloads()
when I attempt to run it I get a very long error:
Traceback (most recent call last):
File "main.py", line 27, in <module>
pages[currentPage].loads(window)
_cnfmerge: fallback due to: 'element' object is not iterable
Traceback (most recent call last):
File "/usr/lib/python3.8/tkinter/__init__.py", line 111, in _cnfmerge
cnf.update(c)
TypeError: 'element' object is not iterable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 27, in <module>
pages[currentPage].loads(None)
File "/home/runner/Phoebe-Hacking-Puzzle/tkml.py", line 10, in loads
child.loads(self)
File "/home/runner/Phoebe-Hacking-Puzzle/tkml.py", line 8, in loads
self.load(self.widget, parent)
_cnfmerge: fallback due to: 'element' object is not iterable
Traceback (most recent call last):
File "/usr/lib/python3.8/tkinter/__init__.py", line 111, in _cnfmerge
cnf.update(c)
TypeError: 'element' object is not iterable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 27, in <module>
pages[currentPage].loads(window)
File "/home/runner/Phoebe-Hacking-Puzzle/tkml.py", line 10, in loads
child.loads(self)
File "/home/runner/Phoebe-Hacking-Puzzle/tkml.py", line 8, in loads
self.load(self.widget, parent)
Traceback (most recent call last):
File "main.py", line 27, in <module>
pages[currentPage].loads(window)
File "/home/runner/Phoebe-Hacking-Puzzle/tkml.py", line 8, in loads
self.load(self.widget, parent)
File "main.py", line 24, in <lambda>
], lambda widget, parent: widget.place(parent, relx = 0, rely = 0, relwidth = 1, relheight = 1))
File "/usr/lib/python3.8/tkinter/__init__.py", line 2439, in place_configure
self.tk.call(
_tkinter.TclError: unknown option "-bd"
I have tried debugging by wading into tkinter's source code and while I have successfully tracked down the line of code that the error comes from, I have no idea where this -bd has come from or what it means. I am new to tkinter, always having used pygame in the past, so there is a good chance I am simply using a function wrong, I would appreciate any help anyone can provide.
PS: I am running my code off repl.it if that makes any difference.

line 17, in __init__ self.win = tk.Tk() TypeError: __init__() takes 2 positional arguments but 3 were given

I'm trying to create a desktop interface using tkinter. I have used all the tips on the websites for this problem. It didn't help in any way.
The error is given up by the line: win = tk.Tk(). What should I do to make the code work? Full code: https://drive.google.com/drive/folders/1NoUBRFDc76WA1rkUSV5_602drRj9P3f6?usp=sharing
win = tk.Tk()
win.title('wave simualator')
win.geometry('1024x650')
# win.resizable(False, False)
tabControl = ttk.Notebook(win)
tab1 = ttk.Frame(tabControl)
tab2 = ttk.Frame(tabControl)
win.mainloop()
Full error traceback:
Traceback (most recent call last):
File "C:\Users\Admin\PycharmProjects\13\main.py", line 213, in <module>
win = tk.Tk()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2272, in __init__
self._loadtk()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2306, in _loadtk
self.protocol("WM_DELETE_WINDOW", self.destroy)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2194, in wm_protocol
command = self._register(func)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1517, in _register
f = CallWrapper(subst, func,).__call__
TypeError: __init__() takes 2 positional arguments but 3 were given

Exception in Tkinter callback /// image = numpy.ndarray(image).astype(int) TypeError: only integer scalar arrays can be converted to a scalar index

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\python\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "C:\Users\umutc\PycharmProjects\pythonProject2\main.py", line 178, in <lambda>
classify_b = Button(top, text="Görseli Sınıflandır", command=lambda: classify(file_path), padx=10, pady=10)
File "C:\Users\umutc\PycharmProjects\pythonProject2\main.py", line 166, in classify
image = numpy.ndarray(image).astype(int)
TypeError: only integer scalar arrays can be converted to a scalar index
# Classifier Function / Sınıflandırma Fonksiyonu
def classify(file_path):
global label_packed
image = Image.open(file_path)
image = image.resize((32,32))
image = numpy.expand_dims(image, axis=0)
image = numpy.array(image)
pred = model.predict_classes([image])[0]
sign = classes[pred]
print(sign)
label.configure(foreground='#FF0000', text=sign,background='#000000',font ="Verdana 20 bold")
label.pack(padx=10,pady=10,side=RIGHT,anchor=NE)

tkinter.font module object not callable

I'm attempting to make a simple platformer game, however, I can't show the "Game Over" message because tkinder, and more specifically, tkfont, or tkinder.font, is a module, and cannot be called.
Code here. The full traceback is:
Traceback (most recent call last):
File "C:\Users\iD Student\Desktop\Connor M\Endless platformer.py", line
31, in <module>
helv36 = tkinter.font(family="Helvetica",size=36,weight="bold")
TypeError: 'module' object is not callable
tkinter.font.Font throws this traceback:
Traceback (most recent call last):
File "C:\Users\iD Student\Desktop\Connor M\Endless platformer.py", line
31, in <module>
helv36 = tkinter.font.Font(family="Helvetica",size=36,weight="bold")
File "C:\Python35\lib\tkinter\font.py", line 93, in __init__
tk.call("font", "create", self.name, *font)
AttributeError: 'NoneType' object has no attribute 'call'
which I assume to be an error in tkinter itself. Relevant code:
import tkinter
from tkinter.font import *
helv36 = tkinter.font.Font(family="Helvetica",size=36,weight="bold")
def draw_text(display_string, font, surface, x_pos, y_pos):
text_display = font.font(display_string, 1, (0, 0, 0))
surface.blit(text_display, (x_pos, y_pos))
#Ends the game if the player dies
if y >640:
endgame = True
if endgame:
draw_text("GAME OVER", helv36, screen, 50, 50)
You can't create a font until after you've created a root window.

cImage python module error

I'm writing a function to convert and display an image to negative, when i call the function i get this error message:
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/Librophyton/Procdeimagenes/test.py",line 32, in <module>
makeNegative(dude)
File "C:\Python34\lib\ImageProcess.py", line 16, in makeNegative
old = FileImage(imageFile)
File "C:\Python34\lib\cImage.py", line 398, in __init__
super(FileImage, self).__init__(fname = thefile)
File "C:\Python34\lib\cImage.py", line 241, in __init__
self.loadImage(fname)
File "C:\Python34\lib\cImage.py", line 270, in loadTkImage
sufstart = fname.rfind('.')
AttributeError: 'FileImage' object has no attribute 'rfind'
Here is the function:
def makeNegative(imageFile):
window = ImageWin("Proceso de imagen", 1000-100, 900)
old = FileImage(imageFile)
old.draw(window)
window.exitOnClick()
w = old.getWidth()
h = old.getHeight()
new = EmptyImage(w,h)
for row in range(h):
for col in range(w):
pixelviejo = old.getPixel(col,row)
pixelnuevo = pixelNeg(pixelviejo)
new.setPixel(col, row, pixelnuevo)
new.setPosition(w+1, 0)
new.draw(window)
window.exitOnClick()
And here is the funciton call:
dude = FileImage("factores_de_conversion.gif" )
makeNegative(dude)
Any idea how to solve this? or how should i modify the module?

Categories