0
votes

The program I am working with currently requires input from the user to be displayed on the programs window. I have researched on both the internet and stackoverflow, discovering several solutions to my problem, but none seem to work. My goal is to receive input from the user via Python's tkinter entry widget and display the results in a new label, while taking out my initial one and the entry box, however, the program is rejecting my attempts at an answer.

What strategy, lines of code/library's, or pieces of advice do you have for me to accomplish my goal?

My existing solutions:

.get()
textvariable=self.entdat

Existing code is as follows:

from Tkinter import *
import time

class Input(Frame):

  def __init__(self, parent=None, **kw):
    Frame.__init__(self, parent, background="white")
    self.parent = parent
    self.initUI()
    self.entdat = StringVar
    self.timestr = StringVar()
    self.makeWidgets()

def makeWidgets(self):
    self.ol = Label(text="Objective:")
    self.ol.pack(side=TOP)
    self.ew = Entry()
    self.ew.pack(side=TOP)
    self.b = Button(text="OK", command=self.clicked)
    self.b.pack(side=TOP)

def clicked(self):
    self.entdat = self.ew.get()
    self.dat = Label(textvariable=self.ew.get())
    self.dat.pack(side=TOP)
    self.hide_Widget()


def hide_Widget(event):
    event.ew.pack_forget()
    event.ol.pack_forget()
    event.b.pack_forget()

def main():
root = Tk()
root.geometry("240x135+25+50")
tm = Input(root)
tm.pack(side=TOP)

root.mainloop()

if __name__ == '__main__':
    main()
1
What is self.initUI()? Its not defined in the code you provided.Marcin
Sorry about that. I only included the part of my program which contained the problem. self.intitUI() sets the parent.title to "Input".Rick_Roll

1 Answers

0
votes

I amended your code, so that it executes at least, and hopefully in a way you want.

from Tkinter import *

class Input(Frame):
    def __init__(self, parent=None, **kw):
        Frame.__init__(self, parent, background="white")
        self.parent = parent
        self.entdat = StringVar()
        self.makeWidgets()

    def makeWidgets(self):
        self.ol = Label(text="Objective:")
        self.ol.pack(side=TOP)
        self.ew = Entry(textvariable=self.entdat)
        self.ew.pack(side=TOP)
        self.b = Button(text="OK", command=self.clicked)
        self.b.pack(side=TOP)

    def clicked(self):
        self.dat = Label(self, textvariable=self.entdat )
        self.dat.pack(side=TOP)
        self.distroy_Widget()


    def distroy_Widget(self):
        self.ew.destroy()
        self.ol.destroy()
        self.b.destroy()

def main():
    root = Tk()
    root.geometry("240x135+25+50")
    tm = Input(root)
    tm.pack(side=TOP)

    root.mainloop()

if __name__ == '__main__':
    main()

Hope it helps.