Python Forum
Need Answers - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Need Answers (/thread-3103.html)



Need Answers - 20nick20 - Apr-29-2017

Why is it opening the other file but not displaying the buttons before or after the code?
from tkinter import *



master = Tk()
class App:
  def __init__(self, master):
    frame = Frame(master)
    frame.pack()
    self.button = Button(frame, 
                         text="How To Do UR Forms", fg="green",
                         command=exec(open("Birthday%20card.py").read()))
    self.button.pack(side=LEFT)
    self.slogan = Button(frame,
                         text="I know my forms",
                         command=self.write_slogan)
    self.slogan.pack(side=LEFT)
  def write_slogan(self):
    answer = input("Imperfect Subjunctive passive of Audio")
    while answer != "Audirer":
        answer = input("Imperfect Subjunctive passive of Audio")    
        print ("Well Done")
        
    
root = Tk()
app = App(root)
root.mainloop()



RE: Need Answers - ichabod801 - Apr-29-2017

I'm getting a syntax error on the exec call that I don't quite understand. Maybe it's because I don't have the right file. But I'm not sure why you're using it. The return value of exec is None, so you're button wouldn't do anything anyway.


RE: Need Answers - Larz60+ - Apr-29-2017

why are you trying to create two instances of Tk()?
That will get you nothing but trouble.
you have:
master = Tk()
# and then
root = Tk()
you never use master for anything anyway

And as Icabod801 points out, what's going on with the exec? what are you trying to accomplish here?


RE: Need Answers - 20nick20 - Apr-29-2017

I wanted it to open that file when the button was clicked but it opens the file first and then the buttons don't appear.


RE: Need Answers - ichabod801 - Apr-29-2017

You should create a function that opens that file, and then assign the function (without calling it) to the command parameter.

I'm not sure about the buttons not showing. Might bee the double Tk().


RE: Need Answers - 20nick20 - Apr-29-2017

Ok Thank You It works now


RE: Need Answers - Larz60+ - Apr-29-2017

The second time you open a top level window, it must be named Toplevel.
see: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/toplevel.html