Basic Class + Dialogs doubt

M

mahesh

Hi all,

I have a doubt with OOAD and Dialogs. I have a Dialog Class.
tkSimple.py
It contains a class body as below. Now I am calling the tkSimple.py in
another python program and using the default body, and everything from
tkSimple.py.

Now my requirement is as follows I need to popup a couple of other
dialog boxes with a little difference in between each dialog and take
different values.

Summarising as below

Main window ----> tkSimple.py
Main window--ButtonClick ---> New dialog 1
Main window--Button 2 Click---> Another New Dialog 2.

Now I am wondering how I can put three different types of dialogs in
the same tksimple.py and call them at different conditions in my main
class

I am including the code here. Right now I have created multiple copies
of the tkSimple.py like tkSimple1.py tkSimple2.py and importing them
whereever I need them

regards,
Mahesh

Main Program
---------------

from Tkinter import *
from tkSimpleDialog import Dialog
import tkMessageBox
import tkSimple


class SampleDialog(tkSimple.Dialog):
......................
...................
..................
def body(self, master):
self.title("Tool ")
self.geometry("400x500")
# All the constant values goes here.
# Labels
Label(master, text='BSS ATTRIB TOOL').grid(row=1, sticky=W)
Label(master, text=' ').grid(row=2, sticky=W)
Label(master, text=' ').grid(row=3, sticky=W)
Label(master, text=' ').grid(row=4, sticky=W)
Label(master, text='BSS Name').grid(row=5, sticky=W)
Label(master, text='MIT VErsion').grid(row=6, sticky=W)
#Choosing the device type belonging to which class goes here.
v = IntVar()
global CnType
CnType = IntVar()
Label(master, text='').grid(row=7, sticky=W)
Label(master, text='').grid(row=8, sticky=W)
Label(master, text='Select a button below to add a
device').grid(row=9,
sticky=W)
optTp = Button(master, text ="Click here to add a Class A
device", comma
nd=self.ShowA).grid(row=10, column=0, sticky=W)
@

def apply(self):
Name1 = self.bssName.get()
Name2 = self.mitName.get()
global CnType
global deviceClass
deviceClass = CnType.get()
print deviceClass

#Boby's Code to place the above values in the file pass
def ShowA(self):
global DialogType
DialogType = 2

getValue = tkSimple1.Dialog(self)

-------------..............end of main program

TkSimple.py Code
-----------------------------

from Tkinter import *
import os

class Dialog(Toplevel):

def __init__(self, parent, title = None):

Toplevel.__init__(self, parent)
self.transient(parent)

if title:
self.title(title)

self.parent = parent

self.result = None

body = Frame(self)

self.initial_focus = self.body(body)
body.pack(padx=5, pady=5)

self.buttonbox()
self.protocol("WM_DELETE_WINDOW", self.cancel)
self.geometry("+%d+%d" % (parent.winfo_rootx()+50,
parent.winfo_rooty(
)+50))
self.initial_focus.focus_set()

self.wait_window(self)


# construction hooks

def body(self, master):
# create dialog body. return widget that should have intial
focus.
pass

def buttonbox(self):
box = Frame(self)
w = Button(box, text="Save", width=10, command=self.ok,
default=ACTIVE)
w.pack(side=LEFT, padx=5, pady=5)

#Need to change the command here .<Mahesh>

w = Button(box, text="Run Tool", width=10, command=self.ok)
w = Button(box, text="Run Tool", width=10, command=self.ok)
w.pack(side=LEFT, padx=5, pady=5)

#w = Button(box, text="Help", width=10, command=self.help)
#w.pack(side=LEFT, padx=5, pady=5)

w = Button(box, text="Cancel", width=10, command=self.cancel)
w.pack(side=LEFT, padx=5, pady=5)

self.bind("&lt;Return.", self.ok)
self.bind("&lt:Escape.", self.cancel)

box.pack()


def ok(self, event=None):

if not self.validate():
self.initial_focus.focus_set()
return

self.withdraw()
self.update_idletasks()
self.apply()
self.cancel()


def cancel(self, event=None):
self.parent.focus_set()
self.destroy()

def validate(self):
return 1

def apply(self):
pass
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top