-2

I just want to create a program, so that when I click the "Print" Button, it takes data from an entry field and outputs to a text field below. Is there something wrong with my usage of .get()? Not exactly sure what's the problem?

import tkinter as tk
from tkinter import *

wd=tk.Tk()

def inkq():
    string= str(nd.get())
    ketqua.insert(END, string)

nd=Entry(wd).pack()
btn=Button(wd, text ="Print", command = inkq).pack()
btn1=Button(wd, text ="Quit", command = wd.destroy).pack()
ketqua=Text(wd, height =10, width = 40).pack()

wd.mainloop()
emilanov
  • 362
  • 4
  • 15

1 Answers1

1

The problem is that .pack() returns None, which does not have a get method. Which can be seen in the following error print from when I ran your code.

AttributeError: 'NoneType' object has no attribute 'get'

import tkinter as tk
from tkinter import *

wd=tk.Tk()

def inkq():
    string= str(nd.get())
    ketqua.insert(END, string)
nd=Entry(wd) #Save entry befor packing
nd.pack()

btn=Button(wd, text ="Print", command = inkq).pack()
btn1=Button(wd, text ="Quit", command = wd.destroy).pack() 
ketqua=Text(wd, height =10, width = 40) #Save entry before packing
ketqua.pack()

wd.mainloop()
Svavelsyra
  • 140
  • 8