Hi ,
Currenty I am storing the Graphical User Interface options in a string memeber variable of a class as show below: - SampleCode
-
Tkinter Modules ( Graphical User Interface):
-
-------------------------------------------------------------
-
a) File.py
-
class File:
-
def __init__(self):
-
self.__strInputFileName = ''
-
self.__strOutputFileName = ''
-
self.__xVal = 0.0
-
self.__yVal = 0.0
-
self.__zVal = 0.0
-
-
def set_input_file_name(self,strInFileName):
-
self.__strInputFileName = strInFileName
-
-
def set_output_file_name(self,strOutFileName):
-
self.__strOutputFileName = strOutFileName
-
-
def set_x_value(self,dXVal):
-
self.__xVal = dXVal
-
-
def set_y_value(self,dYVal):
-
self.__yVal = dYVal
-
-
def set_z_value(self,dzVal):
-
self.__zVal = dZVal
-
-
def get_input_file_name(self):
-
return self.__strInputFileName
-
-
def get_output_file_name(self):
-
return self.__strOutputFileName
-
-
def get_x_value(self):
-
return self.__xVal
-
-
def get_y_value(self):
-
return self.__yVal
-
-
def get_z_value(self):
-
return self.__zVal
-
-
b) FileGUI.py
-
-
class FileGUI:
-
def __init__(self):
-
pass
-
-
def store_values(self):
-
objFile = File()
-
# var1,var2,var3..var5 are the widget variables
-
objFile.set_input_file_name(var1.get())
-
objFile.set_output_file_name(var2.get())
-
objFile.set_x_value(var3.get())
-
objFile.set_y_value(var4.get())
-
objFile.set_z_value(var5.get())
-
return objFile
-
-
def call_fucntion():
-
objTest = TestFunctionality()
-
objTest.do_functionality(store_values())
-
-
c) Main.py
-
class TestFunctionality:
-
def __init__(self):
-
pass
-
-
def do_functionality(self,objFile):
-
objFile = File()
-
-
print objFile.get_input_file_name()
-
print objFile.get_output_file_name(var2.get())
-
print objFile.get_x_value(var3.get())
-
print objFile.get_y_value(var4.get())
-
print objFile.get_z_value(var5.get())
-
or I can store in the dict - SampleCode-2
-
a) FileDict.py
-
-
class FileDict:
-
def __init__(self):
-
pass
-
-
def store_values(self):
-
ParaDict={}
-
ParaDict['InputFileName']=var1.get()
-
ParaDict['OututFileName']=var2.get()
-
ParaDict['XVal']=var3.get()
-
ParaDict['YVal']=var4.get()
-
ParaDict['ZVal']=var5.get()
-
return ParaDict
-
-
def call_fucntion():
-
objTest = TestFunctionality()
-
objTest.do_functionality(store_values())
-
-
b) TestFunctionality.py
-
class TestFunctionality:
-
def __init__(self):
-
pass
-
-
def do_functionality(self,objFile):
-
objFile = File()
-
-
print ParaDict['InputFileName']
-
print ParaDict['OututFileName']
-
print ParaDict['XVal']
-
print ParaDict['YVal']
-
print ParaDict['ZVal']
-
-
Could anybody suggest which is the best way of storing the wedget options and try to use in the functionality
Thanks
PSB
6 1817
Hi ,
Currenty I am storing the Graphical User Interface options in a string memeber variable of a class as show below:
- SampleCode
-
Tkinter Modules ( Graphical User Interface):
-
-------------------------------------------------------------
-
a) File.py
-
class File:
-
def __init__(self):
-
self.__strInputFileName = ''
-
self.__strOutputFileName = ''
-
self.__xVal = 0.0
-
self.__yVal = 0.0
-
self.__zVal = 0.0
-
-
def set_input_file_name(self,strInFileName):
-
self.__strInputFileName = strInFileName
-
-
def set_output_file_name(self,strOutFileName):
-
self.__strOutputFileName = strOutFileName
-
-
def set_x_value(self,dXVal):
-
self.__xVal = dXVal
-
-
def set_y_value(self,dYVal):
-
self.__yVal = dYVal
-
-
def set_z_value(self,dzVal):
-
self.__zVal = dZVal
-
-
def get_input_file_name(self):
-
return self.__strInputFileName
-
-
def get_output_file_name(self):
-
return self.__strOutputFileName
-
-
def get_x_value(self):
-
return self.__xVal
-
-
def get_y_value(self):
-
return self.__yVal
-
-
def get_z_value(self):
-
return self.__zVal
-
-
b) FileGUI.py
-
-
class FileGUI:
-
def __init__(self):
-
pass
-
-
def store_values(self):
-
objFile = File()
-
# var1,var2,var3..var5 are the widget variables
-
objFile.set_input_file_name(var1.get())
-
objFile.set_output_file_name(var2.get())
-
objFile.set_x_value(var3.get())
-
objFile.set_y_value(var4.get())
-
objFile.set_z_value(var5.get())
-
return objFile
-
-
def call_fucntion():
-
objTest = TestFunctionality()
-
objTest.do_functionality(store_values())
-
-
c) Main.py
-
class TestFunctionality:
-
def __init__(self):
-
pass
-
-
def do_functionality(self,objFile):
-
objFile = File()
-
-
print objFile.get_input_file_name()
-
print objFile.get_output_file_name(var2.get())
-
print objFile.get_x_value(var3.get())
-
print objFile.get_y_value(var4.get())
-
print objFile.get_z_value(var5.get())
-
or I can store in the dict - SampleCode-2
-
a) FileDict.py
-
-
class FileDict:
-
def __init__(self):
-
pass
-
-
def store_values(self):
-
ParaDict={}
-
ParaDict['InputFileName']=var1.get()
-
ParaDict['OututFileName']=var2.get()
-
ParaDict['XVal']=var3.get()
-
ParaDict['YVal']=var4.get()
-
ParaDict['ZVal']=var5.get()
-
return ParaDict
-
-
def call_fucntion():
-
objTest = TestFunctionality()
-
objTest.do_functionality(store_values())
-
-
b) TestFunctionality.py
-
class TestFunctionality:
-
def __init__(self):
-
pass
-
-
def do_functionality(self,objFile):
-
objFile = File()
-
-
print ParaDict['InputFileName']
-
print ParaDict['OututFileName']
-
print ParaDict['XVal']
-
print ParaDict['YVal']
-
print ParaDict['ZVal']
-
-
Could anybody suggest which is the best way of storing the wedget options and try to use in the functionality
Thanks
PSB
BV/Barton,
Any comments on this.
Thanks
-PSB
BV/Barton,
Any comments on this.
Thanks
BV/Barton,
Any comments on this.
Thanks
Yes. I like the dictionary for organizing your variables. I use it quite often (almost as you have done here).
Yes. I like the dictionary for organizing your variables. I use it quite often (almost as you have done here).
Thanks Barton,
How about the first method of writing the code for storing the data?
-PSB
Thanks Barton,
How about the first method of writing the code for storing the data?
-PSB
Here's my favorite way to use a class (much like a C structure): -
>>> class FileDetails:
-
... def __init__(self, fname, **more_details):
-
... self.fname = fname
-
... for key, value in more_details.items():
-
... self.__dict__[key] = value
-
...
-
>>> myFileDetails = FileDetails("somefile", filesize = 1024)
-
>>> myFileDetails.fname
-
'somefile'
-
>>> myFileDetails.filesize
-
1024
-
>>>
Here's my favorite way to use a class (much like a C structure): -
>>> class FileDetails:
-
... def __init__(self, fname, **more_details):
-
... self.fname = fname
-
... for key, value in more_details.items():
-
... self.__dict__[key] = value
-
...
-
>>> myFileDetails = FileDetails("somefile", filesize = 1024)
-
>>> myFileDetails.fname
-
'somefile'
-
>>> myFileDetails.filesize
-
1024
-
>>>
It works with functions just as well: -
>>> def getValue():
-
... return 12
-
...
-
>>> myFileDetails = FileDetails("somefile", filesize = 1024, value_getter=getValue)
-
>>> myFileDetails.value_getter()
-
12
-
>>>
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
53 posts
views
Thread by Paul Rubin |
last post: by
|
1 post
views
Thread by Pekka Niiranen |
last post: by
|
reply
views
Thread by Svenn Bjerkem |
last post: by
| | | | | | | | | | | |