I'm trying to create a simple yes/no dialog box - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: I'm trying to create a simple yes/no dialog box (/thread-9596.html) Pages:
1
2
|
I'm trying to create a simple yes/no dialog box - RedSkeleton007 - Apr-18-2018 NOTE: I'm not doing anything illegal. I'm just working with my own two computers. I'm working on a remote access computer hacking program for a school project. I need a way to get the victim computer user to trigger a backdoor shell program. Here's my code so far: #!/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) button1 = tk.Button(frame, text="Yes", command=clickButton1) button2 = tk.Button(frame, text="No", command=clickButton2) button1.pack() button2.pack() def clickButton1(): root.title("You dinks have been hacked!") def clickButton2(): root.destroy()The error is this: For now, I want to pop up a window with yes and no buttons, and text above the buttons that says, "Do you trust the program that wants access to this computer?", rather than have it be the title of the dialog box as it is now due to line 7 in my code.If the user clicks yes, I want the yes and no button dialog box to disappear, and a new dialog box that says, "You have been hacked!" with an ok button that closes that dialog box when the user clicks it. Can someone please help me out? RE: I'm trying to create a simple yes/no dialog box - Larz60+ - Apr-18-2018 Use tkinter.errormessage.askyesno Here's a simple example: import tkinter as tk import tkinter.messagebox as tm class Message: def __init__(self, parent=None): if parent is None: self.parent = tk.Tk() else: self.parent = parent result = self.show_error('Just a Message Box', 'My Message') print(result) def show_error(self, title, message): return tm.askyesno(title, message) if __name__ == '__main__': Message() RE: I'm trying to create a simple yes/no dialog box - RedSkeleton007 - Apr-19-2018 The code in Larz60+'s post produced the same unwanted result as my following updated code: #!/usr/bin/python #BackdoorLogin_DialogBox.py from tkinter import * import tkinter.messagebox import sys root = Tk() answer = tkinter.messagebox.askquestion('Program from unknown source.', 'Do you want to allow this program ' + 'access to your computer?') if answer == 'Yes': print("Yes.") tkinter.messagebox.showinfo('Program activated.', 'You have been hacked!') #activate BackdoorLogin.py elif answer == 'No': print("No.") tkinter.messagebox.showinfo('Program from unknown source.', 'Program denied access by recipient.')After the yes or no button was clicked, The message box disappears and leaves only the box circled in red open: [attachment=398] And why is that box circled in red there anyway? It's a bit of an eyesore if you ask me. Also, with all due respect, please respond with code that's easier to understand than Larz60+'s post, as I'm still brand new to GUIs. Thank you. RE: I'm trying to create a simple yes/no dialog box - Larz60+ - Apr-19-2018 after line 12 (in my code) add: self.parent.withdraw()That should do the trick RE: I'm trying to create a simple yes/no dialog box - RedSkeleton007 - Apr-19-2018 (Apr-19-2018, 05:07 AM)Larz60+ Wrote: after line 12 (in my code) add:Sorry, but that didn't do anything. RE: I'm trying to create a simple yes/no dialog box - Larz60+ - Apr-19-2018 Make sure indentation is correct for this (8 spaces). It works fine on my system. RE: I'm trying to create a simple yes/no dialog box - RedSkeleton007 - Apr-19-2018 For some reason, despite defining all of the buttons, labels, and packing them, my window comes up blank when I run the program: #!/usr/bin/python #BackdoorLogin_DialogBox.py import tkinter as tk#for python 2, it's import Tkinter as tk from tkinter import ttk import sys myFont = ("Verdana", 10) class MyWindows(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) container = tk.Frame(self) container.pack(side="top", fill="both", expand=True) container.grid_rowconfigure(0, weight=1) container.grid_columnconfigure(0, weight=1) self.frames = {}#assign self.frames to an empty dictionary frame = myWindow(container, self) self.frames[myWindow] = frame frame.grid(row=0, column=0, sticky="nsew")#nsew = north south east west self.show_frame(myWindow) def show_frame(self, cont): frame = self.frames[cont]#cont means container, NOT controller. frame.tkraise() def functionTest(): print("Function invoked successfully.") def popupmsg(): popup = tk.Tk() def activateBackdoor(): #code to invoke BackdoorLogin.py goes here. popup.destroy() #myWindow.destroy() popup.wm_title("Program activated.") label = ttk.Label(popup, text="You have been hacked!") label.pack(side="top", fill="x", pady=10) button1 = ttk.Button(popup, text="Ok", command=activateBackdoor) button1.pack() popup.mainloop() def myWindow(): myWindow = tk.Tk() myWindow.wm_title(self, "Program from unknown source.") label1 = ttk.Label(self, text="Program from an unknown source.", font=myFont) label1.pack(pady=10,padx=10) label2 = ttk.Label(self, text="Do you want to allow this program to access your computer?", font=myFont) label2.pack(pady=10,padx=10) button1 = ttk.Button(self, text="yes", command=popupmsg) button2 = ttk.Button(self, text="no", command=myWindow.destroy) button1.pack() button2.pack() myWindow.mainloop() def main(): myWindow() main() firstWindow = MyWindows() firstWindow.mainloop()With these errors: I'm exhausted. Why is this so difficult? What I want to do is so simple:1. A yes or no dialog box comes up. 2. if the user clicks yes, the intitial dialog box disappears, and a message box pops up saying, "You have been hacked!" and then disappears when the user clicks the Ok button and ends the program. 3. if the user clicks no, the initial dialog box disappears and ends the program. THAT'S IT! That's ALL I'VE WANTED to accomplish for the last 6+ hours!!! RE: I'm trying to create a simple yes/no dialog box - Larz60+ - Apr-19-2018 remove 'self.' from line 56, 57, 59, 62 and 64 RE: I'm trying to create a simple yes/no dialog box - woooee - Apr-19-2018 deleted as OP is using code found elsewhere, so as not to confuse this code with it. RE: I'm trying to create a simple yes/no dialog box - nilamo - Apr-19-2018 (Apr-18-2018, 07:21 AM)RedSkeleton007 Wrote: NOTE: I'm not doing anything illegal. I'm just working with my own two computers.Nothing you said is illegal, anyway, even if they aren't your computers. |