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
#7
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:
Error:
=== RESTART: I:\Python\Python36-32\SamsPrograms\BackdoorLogin_DialogBox.py === Traceback (most recent call last): File "I:\Python\Python36-32\SamsPrograms\BackdoorLogin_DialogBox.py", line 74, in <module> main() File "I:\Python\Python36-32\SamsPrograms\BackdoorLogin_DialogBox.py", line 72, in main myWindow() File "I:\Python\Python36-32\SamsPrograms\BackdoorLogin_DialogBox.py", line 56, in myWindow myWindow.wm_title(self, "Program from unknown source.") NameError: name 'self' is not defined >>>
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!!!
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  How a QMainWindow can open a dialog? panoss 4 3,639 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,432 Jul-17-2021, 09:17 PM
Last Post: steve_shambles
  How to create a simple GUI GRS26 7 3,686 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,285 Apr-03-2019, 06:33 PM
Last Post: Yoriz
  Simple Button click on image file to create action? jpezz 4 6,956 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