By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,286 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,286 IT Pros & Developers. It's quick & easy.

Best way of storing Tkinter Graphical User Interface Widget option data

100+
P: 440
Hi ,

Currenty I am storing the Graphical User Interface options in a string memeber variable of a class as show below:

Expand|Select|Wrap|Line Numbers
  1. SampleCode
  2. Tkinter Modules ( Graphical User Interface):
  3. -------------------------------------------------------------
  4. a) File.py
  5. class File:
  6.     def __init__(self):
  7.         self.__strInputFileName = ''
  8.         self.__strOutputFileName = ''
  9.         self.__xVal = 0.0
  10.         self.__yVal = 0.0
  11.         self.__zVal = 0.0
  12.  
  13.     def set_input_file_name(self,strInFileName):
  14.         self.__strInputFileName = strInFileName
  15.  
  16.     def set_output_file_name(self,strOutFileName):
  17.         self.__strOutputFileName = strOutFileName
  18.  
  19.     def set_x_value(self,dXVal):
  20.         self.__xVal = dXVal
  21.  
  22.     def set_y_value(self,dYVal):
  23.         self.__yVal = dYVal
  24.  
  25.     def set_z_value(self,dzVal):
  26.         self.__zVal = dZVal
  27.  
  28.     def get_input_file_name(self):
  29.         return self.__strInputFileName 
  30.  
  31.     def get_output_file_name(self):
  32.         return  self.__strOutputFileName
  33.  
  34.     def get_x_value(self):
  35.         return self.__xVal 
  36.  
  37.     def get_y_value(self):
  38.         return self.__yVal 
  39.  
  40.     def get_z_value(self):
  41.         return self.__zVal 
  42.  
  43. b) FileGUI.py
  44.  
  45. class FileGUI:
  46.     def __init__(self):
  47.         pass
  48.  
  49.     def store_values(self):
  50.         objFile = File()
  51.         # var1,var2,var3..var5 are the widget variables
  52.         objFile.set_input_file_name(var1.get())
  53.         objFile.set_output_file_name(var2.get())
  54.         objFile.set_x_value(var3.get())
  55.         objFile.set_y_value(var4.get())
  56.         objFile.set_z_value(var5.get())
  57.         return   objFile      
  58.  
  59.     def call_fucntion():
  60.          objTest = TestFunctionality()
  61.          objTest.do_functionality(store_values())
  62.  
  63. c) Main.py
  64. class TestFunctionality:
  65.     def __init__(self):
  66.         pass
  67.  
  68.     def do_functionality(self,objFile):
  69.         objFile = File()
  70.  
  71.         print objFile.get_input_file_name()
  72.         print objFile.get_output_file_name(var2.get())
  73.         print objFile.get_x_value(var3.get())
  74.         print objFile.get_y_value(var4.get())
  75.         print objFile.get_z_value(var5.get())
  76.  
or I can store in the dict

Expand|Select|Wrap|Line Numbers
  1. SampleCode-2
  2. a) FileDict.py
  3.  
  4. class FileDict:
  5.     def __init__(self):
  6.         pass
  7.  
  8.     def store_values(self):
  9.         ParaDict={}
  10.         ParaDict['InputFileName']=var1.get()
  11.         ParaDict['OututFileName']=var2.get()
  12.         ParaDict['XVal']=var3.get()
  13.         ParaDict['YVal']=var4.get()
  14.         ParaDict['ZVal']=var5.get()        
  15.         return   ParaDict              
  16.  
  17.      def call_fucntion():
  18.          objTest = TestFunctionality()
  19.          objTest.do_functionality(store_values())
  20.  
  21. b) TestFunctionality.py
  22. class TestFunctionality:
  23.     def __init__(self):
  24.         pass
  25.  
  26.     def do_functionality(self,objFile):
  27.         objFile = File()
  28.  
  29.         print ParaDict['InputFileName']
  30.         print ParaDict['OututFileName']
  31.         print ParaDict['XVal']
  32.         print ParaDict['YVal']
  33.         print ParaDict['ZVal']
  34.  
  35.  
Could anybody suggest which is the best way of storing the wedget options and try to use in the functionality

Thanks
PSB
Aug 9 '07 #1
Share this Question
Share on Google+
6 Replies

100+
P: 440
Hi ,

Currenty I am storing the Graphical User Interface options in a string memeber variable of a class as show below:
Expand|Select|Wrap|Line Numbers
  1. SampleCode
  2. Tkinter Modules ( Graphical User Interface):
  3. -------------------------------------------------------------
  4. a) File.py
  5. class File:
  6.     def __init__(self):
  7.         self.__strInputFileName = ''
  8.         self.__strOutputFileName = ''
  9.         self.__xVal = 0.0
  10.         self.__yVal = 0.0
  11.         self.__zVal = 0.0
  12.  
  13.     def set_input_file_name(self,strInFileName):
  14.         self.__strInputFileName = strInFileName
  15.  
  16.     def set_output_file_name(self,strOutFileName):
  17.         self.__strOutputFileName = strOutFileName
  18.  
  19.     def set_x_value(self,dXVal):
  20.         self.__xVal = dXVal
  21.  
  22.     def set_y_value(self,dYVal):
  23.         self.__yVal = dYVal
  24.  
  25.     def set_z_value(self,dzVal):
  26.         self.__zVal = dZVal
  27.  
  28.     def get_input_file_name(self):
  29.         return self.__strInputFileName 
  30.  
  31.     def get_output_file_name(self):
  32.         return  self.__strOutputFileName
  33.  
  34.     def get_x_value(self):
  35.         return self.__xVal 
  36.  
  37.     def get_y_value(self):
  38.         return self.__yVal 
  39.  
  40.     def get_z_value(self):
  41.         return self.__zVal 
  42.  
  43. b) FileGUI.py
  44.  
  45. class FileGUI:
  46.     def __init__(self):
  47.         pass
  48.  
  49.     def store_values(self):
  50.         objFile = File()
  51.         # var1,var2,var3..var5 are the widget variables
  52.         objFile.set_input_file_name(var1.get())
  53.         objFile.set_output_file_name(var2.get())
  54.         objFile.set_x_value(var3.get())
  55.         objFile.set_y_value(var4.get())
  56.         objFile.set_z_value(var5.get())
  57.         return   objFile      
  58.  
  59.     def call_fucntion():
  60.          objTest = TestFunctionality()
  61.          objTest.do_functionality(store_values())
  62.  
  63. c) Main.py
  64. class TestFunctionality:
  65.     def __init__(self):
  66.         pass
  67.  
  68.     def do_functionality(self,objFile):
  69.         objFile = File()
  70.  
  71.         print objFile.get_input_file_name()
  72.         print objFile.get_output_file_name(var2.get())
  73.         print objFile.get_x_value(var3.get())
  74.         print objFile.get_y_value(var4.get())
  75.         print objFile.get_z_value(var5.get())
  76.  
or I can store in the dict

Expand|Select|Wrap|Line Numbers
  1. SampleCode-2
  2. a) FileDict.py
  3.  
  4. class FileDict:
  5.     def __init__(self):
  6.         pass
  7.  
  8.     def store_values(self):
  9.         ParaDict={}
  10.         ParaDict['InputFileName']=var1.get()
  11.         ParaDict['OututFileName']=var2.get()
  12.         ParaDict['XVal']=var3.get()
  13.         ParaDict['YVal']=var4.get()
  14.         ParaDict['ZVal']=var5.get()        
  15.         return   ParaDict              
  16.  
  17.      def call_fucntion():
  18.          objTest = TestFunctionality()
  19.          objTest.do_functionality(store_values())
  20.  
  21. b) TestFunctionality.py
  22. class TestFunctionality:
  23.     def __init__(self):
  24.         pass
  25.  
  26.     def do_functionality(self,objFile):
  27.         objFile = File()
  28.  
  29.         print ParaDict['InputFileName']
  30.         print ParaDict['OututFileName']
  31.         print ParaDict['XVal']
  32.         print ParaDict['YVal']
  33.         print ParaDict['ZVal']
  34.  
  35.  
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
Aug 9 '07 #2

100+
P: 440
BV/Barton,

Any comments on this.

Thanks
Aug 9 '07 #3

bartonc
Expert 5K+
P: 6,596
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).
Aug 10 '07 #4

100+
P: 440
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
Aug 10 '07 #5

bartonc
Expert 5K+
P: 6,596
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):
Expand|Select|Wrap|Line Numbers
  1. >>> class FileDetails:
  2. ...     def __init__(self, fname, **more_details):
  3. ...         self.fname = fname
  4. ...         for key, value in more_details.items():
  5. ...             self.__dict__[key] = value
  6. ...             
  7. >>> myFileDetails = FileDetails("somefile", filesize = 1024)
  8. >>> myFileDetails.fname
  9. 'somefile'
  10. >>> myFileDetails.filesize
  11. 1024
  12. >>> 
Aug 10 '07 #6

bartonc
Expert 5K+
P: 6,596
Here's my favorite way to use a class (much like a C structure):
Expand|Select|Wrap|Line Numbers
  1. >>> class FileDetails:
  2. ...     def __init__(self, fname, **more_details):
  3. ...         self.fname = fname
  4. ...         for key, value in more_details.items():
  5. ...             self.__dict__[key] = value
  6. ...             
  7. >>> myFileDetails = FileDetails("somefile", filesize = 1024)
  8. >>> myFileDetails.fname
  9. 'somefile'
  10. >>> myFileDetails.filesize
  11. 1024
  12. >>> 
It works with functions just as well:
Expand|Select|Wrap|Line Numbers
  1. >>> def getValue():
  2. ...     return 12
  3. ... 
  4. >>> myFileDetails = FileDetails("somefile", filesize = 1024, value_getter=getValue)
  5. >>> myFileDetails.value_getter()
  6. 12
  7. >>> 
Aug 10 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.