Problems programming with Tkinter

Discussion in 'Python' started by Svennglenn, Jan 2, 2005.

  1. Svennglenn

    Svennglenn Guest

    Hi !

    I'm trying to create a graphical program using Tkinter.
    The program is supposed to save a string the user defines
    as a filename. I've made it work with the the first button
    in the program that's named "Spara ett värde i en sträng till ett
    filnamn", that's swedish for "Save a value in a string as a file name".
    The button "Skriv ett värde till filen" (swedish for "Write a value to
    the file")

    But, i want the program to open a new dialogue when i press the button
    "Visa ruta" and in that dialogue will be a field where you can enter a
    value directly in the program, but a can't get it to work because is
    don't know how i shall do to open a new dialogue window in the program?
    Is there someone who can help me with my problem?

    Here's the sourcecode for my program:

    from Tkinter import *
    class App:


    def __init__(self, master):

    frame = Frame(master)
    frame.pack()


    self.hi_there = Button(frame, text="Spara ett värde i en
    sträng till ett filnamn", command=self.say_hi)
    self.hi_there.pack(side=LEFT)


    self.skriv_varde = Button(frame, text="Skriv ett värde till
    filen", command=self.skriv_varde)
    self.skriv_varde.pack(side=LEFT)

    self.visa_ruta = Button(frame, text="Visa ruta",
    command=self.visa_ruta)
    self.visa_ruta.pack(side=LEFT)

    def say_hi(self):
    print "Sparar fil"
    S = "filen.fil"
    output = open(S, 'w')
    print "Filen sparad"

    def skriv_varde(self):
    print "Skriver värde till filen"
    myfile = open('filen.fil', 'w')

    myfile.write('Ny mening')
    myfile.close()
    print "Värdet till filen skrivet"


    def visa_ruta(self, parent):

    top = self.top = Toplevel(parent)

    Label(top, text="Value").pack()

    self.e = Entry(top)
    self.e.pack(padx=5)

    b = Button(top, text="OK", command=self.ok)
    b.pack(pady=5)


    def ok(self):

    print "value is", self.e.get()

    self.top.destroy()


    root = Tk()

    app = App(root)
    root.mainloop()
    Svennglenn, Jan 2, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Epler
    Replies:
    0
    Views:
    506
    Jeff Epler
    Aug 20, 2004
  2. Jeff Epler
    Replies:
    0
    Views:
    452
    Jeff Epler
    Aug 23, 2004
  3. Pierre Dagenais
    Replies:
    0
    Views:
    309
    Pierre Dagenais
    Aug 3, 2008
  4. Hidekazu IWAKI
    Replies:
    1
    Views:
    376
    Peter Otten
    Dec 14, 2009
  5. Hidekazu IWAKI
    Replies:
    0
    Views:
    522
    Hidekazu IWAKI
    Dec 15, 2009
Loading...

Share This Page