0

I'm working on my program to make it python3-compliant, but it relies heavily on tkinter and I have a few problems.

I already changed all the import names since many among them were renamed (Which tkinter modules were renamed in Python 3?), but how can I deal with the following?

class PasswordDialog(tkSimpleDialog.Dialog):

I tried changing it to variations of

class PasswordDialog(tkinter.simpledialog.dialog):

but it keeps on telling me that AttributeError: 'module' object has no attribute 'dialog'

(not) working code:

#!/usr/bin/python3

from tkinter import simpledialog

class PasswordDialog(simpledialog.Dialog):                 
    def body(self, master):
        Label(master, text="Password for file "+currentfn).grid(row=0, sticky=W)
        self.e1 = Entry(master,show='*')
        self.e1.grid(row=0, column=1)
        self.attributes("-topmost", True) 
        return self.e1 
    def apply(self):
        p = self.e1.get()
        self.result = p

Result:

AttributeError: 'module' object has no attribute 'Dialog'
alessandro
  • 3,838
  • 8
  • 40
  • 59

1 Answers1

0

Using Python 3.74 on a windows 10 machine. I took your code as is and just defined currentfn and it worked for me. Here is my entire code listing


##  ------------------------------------------------------------------------
##  Generic Template Program
##  ------------------------------------------------------------------------


##  ------------------------------------------------------------------------
##  Imports
##  ------------------------------------------------------------------------
from tkinter import *
from tkinter import ttk

from tkinter import simpledialog


##  ------------------------------------------------------------------------
##  ToDo List
##  ------------------------------------------------------------------------


##  ------------------------------------------------------------------------
##  Constants
##  ------------------------------------------------------------------------
prog_id = {'progname':'Sample Template',
    'title':'Simple gui template',
    'version':'1.0',
    'date':'05 March 2020',
    'rev_date':'',
    'author':'Peter Hedlund',
    'description':'Create simple template file.'}


##  ------------------------------------------------------------------------
##  Variables
##  ------------------------------------------------------------------------
_debug_ = 0
currentfn='test'

##  ------------------------------------------------------------------------
##  Functions
##  ------------------------------------------------------------------------

class PasswordDialog(simpledialog.Dialog):                 
    def body(self, master):
        Label(master, text="Password for file "+currentfn).grid(row=0, sticky=W)
        self.e1 = Entry(master,show='*')
        self.e1.grid(row=0, column=1)
        self.attributes("-topmost", True) 
        return self.e1 
    def apply(self):
        p = self.e1.get()
        self.result = p


   

##  ------------------------------------------------------------------------
##  Controls
##  ------------------------------------------------------------------------


def quit_prog():
    root.destroy()


def test_btn():
    PasswordDialog(root, "Password Test")

##  ------------------------------------------------------------------------
##
##  Main GUI Starts Here
##
##  ------------------------------------------------------------------------
root = Tk()
#  prevent window resizing.
root.resizable(0, 0)
root.title(prog_id['title'] + "  Ver " + prog_id['version'])
mainframe = ttk.Frame(root, padding='3', height=590, width=850)
mainframe.grid(column=1, row=2, sticky=(N, W, E, S))
mainframe.grid_propagate(0)

#  Style Section
s1 = ttk.Style()
s1.configure('red.TButton', background='Red')

#  String variables
fbus_cw = StringVar()

#  Integer variables
reportType = IntVar()

#  Label Widget
lab0 = Label(mainframe, text='', width=15)
lab0.grid(column=0, row=5)

#  Button Widgets
savelog = ttk.Button(mainframe, text='Test', command=test_btn)
savelog.grid(column=0, row=8)
quitProg = ttk.Button(mainframe, text='Quit', style='red.TButton',
                      command=quit_prog)
quitProg.grid(column=0, row=10)

for child in mainframe.winfo_children():
    child.grid_configure(padx=5, pady=5)

root.mainloop()