Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 I'm trying to create a simple yes/no dialog box
#11
Fellas, I found a youtube tutorial that had exactly what I was looking for:

#!/usr/bin/python
#YesNoPopup.py

from tkinter import *
import tkinter.messagebox

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
        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 next move is calling my BackdoorLogin.py program (a reverse shell program for hacking into a victim computer), as commented on line 14. I have used functions from other modules before, but never attempted to invoke a another full program from within another program. Is that possible?

One other thing. The reason I'm doing this is to make the reverse shell program more realistic. Doing so will allow the victim computer user to simply click a couple of buttons rather than go into a terminal and enter ./BackdoorLogin.py.
Quote
#12
Just adjusted your original program so it works.
Your error was because the functions needed to be before the buttons.
I altered the message to be on a label as well.
Also you would have found you saw nothing without the root.mainloop()
I used tkinter a lot but have come to start learning to use wxpython instead as once you start to do more complicated layouts it's much more versatile.
#!/usr/bin/python
#BackdoorLogin_DialogBox.py
 
import tkinter as tk
 
root = tk.Tk()
#root.title("Permit program to access this computer?")
frame = tk.Frame()
frame.pack(fill=tk.BOTH, expand=True)
 
def clickButton1():
    label.configure(text ="You dinks have been hacked!")
 
def clickButton2():
    root.destroy()

label = tk.Label(frame, text = "Permit program to access this computer?")
button1 = tk.Button(frame, text="Yes", command=clickButton1)
button2 = tk.Button(frame, text="No", command=clickButton2)
label.pack()
button1.pack()
button2.pack()
root.mainloop()
Quote
#13
Cool. What about my question in post 11 of how to invoke another python program:

if answer == 'yes':
        tkinter.messagebox.showinfo('Program activated.', 'You have been hacked!')
        #code to activate BackdoorLogin.py
        root.destroy()
Quote
#14
import filename?
Quote
#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?
Quote
#16
Don't call the function inside QuickTest.py. When you import it, python runs all the code in it. And since you call the function, then the function is called as soon as you import it.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [WxPython] Return code when closing the dialog ioprst 1 254 Aug-13-2019, 11:47 AM
Last Post: jefsummers
  PyQT5 : Unable to Create Another Dialog While One is Open iMuny 3 335 Jul-17-2019, 11:40 AM
Last Post: iMuny
  [WxPython] Any dialog that allow user to select file OR folder? buran 3 426 Apr-03-2019, 06:33 PM
Last Post: Yoriz
  Simple Button click on image file to create action? jpezz 4 419 Mar-27-2019, 10:08 PM
Last Post: jpezz
  [WxPython] how to run the dialog from another py file royer14 0 592 Jul-02-2018, 05:33 AM
Last Post: royer14
  FileBrowser dialog reverendfuzzy 5 1,138 May-06-2018, 01:56 PM
Last Post: reverendfuzzy
  About Dialog in PyQt5 on macOS cpuin 0 776 Jan-23-2018, 08:50 PM
Last Post: cpuin
  set font from dialog box pyside python Gigux 1 1,362 May-08-2017, 12:25 AM
Last Post: Joseph_f2
  [PyQt] PyQT5: Open QFiledialog in a Dialog which was create in qt designer nieselfriem 4 9,484 Apr-30-2017, 07:40 PM
Last Post: volcano63

Forum Jump:


Users browsing this thread: 1 Guest(s)