Python Forum
I'm trying to create a simple yes/no dialog box
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I'm trying to create a simple yes/no dialog box
#15
(Apr-24-2018, 06:01 PM)nilamo Wrote: import filename?
Pretty much. It's exactly like importing a module function:
#!/usr/bin/python
#YesNoPopup.py

from tkinter import *
import tkinter.messagebox
import QuickTest as test

def ask_question():
    answer = tkinter.messagebox.askquestion("Program from unknown source.",
                                            "Do you want to allow this " +
                                            "program to access your computer?")

    if answer == 'yes':
        tkinter.messagebox.showinfo('Program activated.', 'You have been hacked!')
        #code to activate BackdoorLogin.py
        test.QuickTestMain()
        root.destroy()
    else:
        tkinter.messagebox.showinfo('You denied the program access.', 'Wise choice!')
        root.destroy()

root = Tk()

btn = Button(root, text="Alert!", command=ask_question)
btn.pack(side=TOP)

root.mainloop()
The QuickTest.py code is:
#!/usr/bin/env python3
#QuickTest.py

def printSomething():
    print("HA-HA-HA! I'm an evil python program.")

def QuickTestMain():
    printSomething()

QuickTestMain()
The only problem is that it prints the message twice, once with the initial "Alert!" message box, and a second time after the user clicks yes:
Error:
========= RESTART: I:\Python\Python36-32\SamsPrograms\YesNoPopup.py ========= HA-HA-HA! I'm an evil python program. HA-HA-HA! I'm an evil python program. >>>
How do I prevent it from printing the message before it goes into the ask_question fucntion?
Reply


Messages In This Thread
RE: I'm trying to create a simple yes/no dialog box - by RedSkeleton007 - Apr-25-2018, 10:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How a QMainWindow can open a dialog? panoss 4 3,638 Feb-03-2022, 04:33 PM
Last Post: panoss
  [Tkinter] question for a tkinter dialog box RobertAlvarez424 2 2,291 Aug-25-2021, 03:08 PM
Last Post: RobertAlvarez424
  [Tkinter] cancelling open dialog gives empty string rwahdan 2 3,431 Jul-17-2021, 09:17 PM
Last Post: steve_shambles
  How to create a simple GUI GRS26 7 3,685 Mar-27-2021, 02:38 PM
Last Post: FernandoCabral
  which is the best library to create a simple web browser? vivekagrey 3 2,449 Jan-11-2020, 05:24 AM
Last Post: vivekagrey
  [WxPython] Return code when closing the dialog ioprst 1 3,224 Aug-13-2019, 11:47 AM
Last Post: jefsummers
  PyQT5 : Unable to Create Another Dialog While One is Open iMuny 3 3,971 Jul-17-2019, 11:40 AM
Last Post: iMuny
  [WxPython] Any dialog that allow user to select file OR folder? buran 3 4,284 Apr-03-2019, 06:33 PM
Last Post: Yoriz
  Simple Button click on image file to create action? jpezz 4 6,955 Mar-27-2019, 10:08 PM
Last Post: jpezz
  [WxPython] how to run the dialog from another py file royer14 0 2,720 Jul-02-2018, 05:33 AM
Last Post: royer14

Forum Jump:

User Panel Messages

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