[英]AttributeError: 'int' object has no attribute 'get' how can i fix it
Hey i tryed to make a canvas in tkinter and make the entry to a global variable but i get the error (AttributeError: 'int' object has no attribute 'get')嘿,我试图在 tkinter 中制作一个画布并输入一个全局变量,但我得到了错误(AttributeError: 'int' object has no attribute 'get')
def a():
a1 = e1.get()
b1 = e2.get()
c1 = e3.get()
print(a, b, c)
def window():
window = Tk()
my_canvas = Canvas(window, width=530, height=240, bd=0, highlightthickness=0)
my_canvas.pack(fill="both", expand=True)
global e1, e2, e3
e1 = Entry(window, fg="black", bd=0)
e2 = Entry(window, fg="black", bd=0)
e3 = Entry(window, fg="black", bd=0)
e1 = my_canvas.create_window(40, 20, anchor="nw", window=e1)
e2 = my_canvas.create_window(40, 60, anchor="nw", window=e2)
e3 = my_canvas.create_window(40, 100, anchor="nw", window=e3)
button1 = Button(window, text='Print', bd=0, bg="black", fg="white", command=a)
button1 = my_canvas.create_window(400, 20, anchor="nw", window=button1)
window.mainloop()
p = Process(target=window)
p.start()
p.join()
You are calling get
on .create_window
object您正在调用
get
on .create_window
对象
You should not run over the Entry
objects:你不应该跑过
Entry
对象:
from tkinter import Tk, Canvas, Button, Entry
from multiprocessing import Process
def a():
a = e1.get()
b = e2.get()
c = e3.get()
print(a, b, c)
def window():
window = Tk()
my_canvas = Canvas(window, width=530, height=240, bd=0, highlightthickness=0)
my_canvas.pack(fill="both", expand=True)
global e1, e2, e3
e1 = Entry(window, fg="black", bd=0)
e2 = Entry(window, fg="black", bd=0)
e3 = Entry(window, fg="black", bd=0)
e1_w = my_canvas.create_window(40, 20, anchor="nw", window=e1)
e2_w = my_canvas.create_window(40, 60, anchor="nw", window=e2)
e3_w = my_canvas.create_window(40, 100, anchor="nw", window=e3)
button1 = Button(window, text='Print', bd=0, bg="black", fg="white", command=a)
button1 = my_canvas.create_window(400, 20, anchor="nw", window=button1)
window.mainloop()
p = Process(target=window)
p.start()
p.join()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.