Python Forum
Thread Rating:
  • 2 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need Answers
#1
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()
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
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?
Reply
#4
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.
Reply
#5
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().
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#6
Ok Thank You It works now
Reply
#7
The second time you open a top level window, it must be named Toplevel.
see: http://infohost.nmt.edu/tcc/help/pubs/tk...level.html
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  'answers 2' is not defined on line 27 0814uu 4 668 Sep-02-2023, 11:02 PM
Last Post: 0814uu
  Division calcuation with answers to 1decimal place. sik 3 2,091 Jul-15-2021, 08:15 AM
Last Post: DeaD_EyE
  Cannot Assign right Answers To Shuffled Questions Boblows 6 2,683 Jan-22-2021, 09:41 AM
Last Post: buran
  Using answers from an input function Totalartist 3 2,139 Jul-19-2019, 02:02 PM
Last Post: snippsat
  Writing Answers From Questionnaire to a new .txt Document FizzyBreak579 4 3,498 Feb-16-2018, 07:26 AM
Last Post: buran
  Code that generates MD5 hashes from IPv6 addresses giving differant answers? PyMD5 4 6,382 Oct-17-2016, 02:39 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020