2 tkinter questions

walter hanagriff walter111 at structurex.net
Thu Jul 20 03:55:13 EDT 2000


if the source of this standalone file should be given to better help me
by running it, then just say so please, i figured not putting the full
source because this part was my only problem area and to save space,
though i guess i talk too much already

i finally figured a way to add stuff to the second frames in the program
i posted earlier, but everytime i make a step forward it seems that i
get stuck again, and i have tried getting past this one several ways as
usual, the one shown here only the latest one, not better or worse then
the other attempts

main problem: i want to make it so that when a person hits a button the
answer pops up in the frame
i set iv1 and iv2 to those numbers for testing, and another problem to
be asked next.
at first the label wasnt in its own def but it was showing 3 { to the
power of } 2 { = } 9 under the 2 entrys before i even hit the button, so
i gigured puttong it in its own def and calling it from the button would
work, but it still shows too soon
what should i do? and what am i doing wrong that makes it do this, i
also tried not packing the label until the button was pressed by giving
the label a name and using bind on the button and using the button
option command = label1.pack()
but it still showed the label like it was reading the button command
even before i clicked on the button, nothing makes sense. i hope i am
making enough sense to be able to get an answer

second problem, how best should i get the value from the entry widgets
after a value is entered, the line that is commented is that way because
when i try to get the value of entry1 through that get method, it says
no value is entered so i cant get the powr of any numbers, and i also
tried using the get method for the textvariable and still get nowhere,
besdies the best way to get an entry variable how to i make it so that
it doesnt get the variables until from the entry widgets until the
button is pressed?

    def power(self, frame):
        entry1 = Entry(frame, width = 10, textvariable = self.ivar1) ;
entry1.pack()
        entry2 = Entry(frame, width = 10, textvariable = self.ivar2) ;
entry2.pack()
#        iv1 = entry1.get() ; iv2 = entry2.get()
        iv1 = 3 ; iv2 = 2
        text = iv1, " to the power of ", iv2, ' = ', iv1**iv2
        def answer(frame, text):
            Label(frame, text = text).pack(padx = 15)
        Button(frame, text = 'Get answer',
               command = answer(frame, text)).pack(side = LEFT)





More information about the Python-list mailing list