#python #string #tkinter #python-requests
Вопрос:
Эй, я попытался создать холст в tkinter и внести запись в глобальную переменную, но я получаю ошибку (ошибка атрибута: объект » int «не имеет атрибута «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()
Ответ №1:
Вы вызываете get
.create_window
объект
Вы не должны наезжать на 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()