By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,222 Members | 2,478 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,222 IT Pros & Developers. It's quick & easy.

Problems programming with Tkinter

P: n/a
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()

Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.