-2

In my program the user is asked for their Name, Surname and High School Class. At the the end of the program there is an if statement and if the condition is met then I would like to create a file which will print these variables as well as a message or two.

I would also like to ask the user to enter a short statement about themselves so basically a text entry and this is to be added to the file also.

class Score_Window(tk.Toplevel):
'''A simple instruction window'''
def __init__(self, parent):
    tk.Toplevel.__init__(self, parent)
    score_str = str(sum(parent.score_per_question.values()))
    self.score = tk.Label(self, width=80, height=4, text = "You're score was: " + score_str)
    self.score.pack(side="top", fill="both", expand=True)


    if int(score_str) >= 3:
        print("Pass")

        self.prefect = tk.Label(self, width=80, height=4, text = "You have passed, well done! You can now become a prefect.")
        self.prefect.pack(side="top", fill="both", expand=True)

        self.name = tk.Label(self, width=80, height=4, text = student_name)
        self.name.pack(side="top", fill="both", expand=True)

        self.surname = tk.Label(self, width=80, height=4, text = student_surname)
        self.surname.pack(side="top", fill="both", expand=True)

        self.tutor = tk.Label(self, width=80, height=4, text = student_tutor_group)
        self.tutor.pack(side="top", fill="both", expand=True)

I want to print these variables to a file

    else:
        print("Fail")

        self.fail = tk.Label(self, width=80, height=4, text = "Unfortunately you have not scored highly enough to be considered for a prefect position.")
        self.fail.pack(side="top", fill="both", expand=True)
Cœur
  • 37,241
  • 25
  • 195
  • 267
user3056786
  • 89
  • 2
  • 10
  • 5
    have you written any code for this so far? What is your actual question? No one wants to just write the code for you if you haven't even had a go yourself. Not trying to be nasty or anything, but you'll learn more by trying yourself first, and coming here for guidance when you're really stuck. I guarantee you'll have actual questions then :) – Totem Jan 06 '14 at 18:36
  • You'll be more successful at finding an answer if you show you've put in some effort solving this on your own. – That1Guy Jan 06 '14 at 18:37
  • Take a shot at coding it yourself first http://docs.python.org/2/tutorial/inputoutput.html come back if you have a specific question. We will not write the code for you from scratch. – Cory Kramer Jan 06 '14 at 18:37
  • `raw_input` is what you are looking for perhaps? – Joran Beasley Jan 06 '14 at 18:37
  • Sorry guys: I have coded it and am almost finished my program which is a ten question multiple choice quiz. I am not looking for someone to code the entire thing but simply an example of how it can be done would be a good help. – user3056786 Jan 07 '14 at 13:52

1 Answers1

0

You can do it using python's open statement and getting input using tksimpiledialog. Assuming you had set up the class:

from Tkinter import * # tkinter in 3.0+
from tkSimpleDialog import askstring

Name = tkSimpleDialog.askstring("User data","Please enter your name")
Surname = tkSimpleDialog.askstring("User data", "Please enter your surname")
somevariable = open("data.txt", "w")
somevariable.write(Name, " ",Surname) # add a space so it is easier to read
userinfo = tkSimpleDialog.askstring("User data", "Enter something about yourself")
somevariable.write(" ",userinfo
# make if statements and a new canvas
with open("data.txt", "r") as l
    for lines in l:
        name2, Surname2, userinfo2 = lines.split()
        namelabel = label(master, text=name2)
        namelabel.pack()
        surnamelable = label(master, text=Surname2)
        surnamelable.pack()
        Userinfolabel = label(master, text= userinfo2)
        Userinfolabel.pack()
        # do whatever you want here, perhaps a reset button?

You'll have to set up the main Tk class and the init manually for i do not know what else your code has. And I do not even know the test condition for the if statements!

Dashadower
  • 632
  • 1
  • 6
  • 20