Home > Software engineering >  AttributeError: 'int' object has no attribute 'get' how can i fix it
AttributeError: 'int' object has no attribute 'get' how can i fix it

Time:10-13

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')

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()

CodePudding user response:

You are calling get on .create_window object

You should not run over the Entry objects:

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()
  • Related