0

I need to take each variable and use it but I'm not sure how print out the result of the outputs. Can someone give me some advice? I'm new with tkinter. Thanks!

import tkinter as tk
from tkinter import simpledialog
from tkinter import *

class MyDialog(simpledialog.Dialog):

    def body(self, master):

        Label(master, text="First:").grid(row=0)
        Label(master, text="Second:").grid(row=1)
        Label(master, text="Third:").grid(row=2)
        Label(master, text="Fourth:").grid(row=3)

        self.e1 = Entry(master)
        self.e2 = Entry(master)
        self.e3 = Entry(master)
        self.e4 = Entry(master)

        self.e1.grid(row=0, column=1)
        self.e2.grid(row=1, column=1)
        self.e3.grid(row=2, column=1)
        self.e4.grid(row=3, column=1)

        return self.e1 # initial focus

    def apply(self):
        first = self.e1.get()
        second = self.e2.get()
        third = self.e3.get()
        fourth =  self.e4.get()


root = tk.Tk()
root.withdraw()
d = MyDialog(root)
print (root)

1 Answer 1

1

You need to set self.result inside apply():

def apply(self):
    first = self.e1.get()
    second = self.e2.get()
    third = self.e3.get()
    fourth =  self.e4.get()
    self.result = (first, second, third, fourth)

Then you can get the result using d.result:

d = MyDialog(root)
print(d.result)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.