473,373 Members | 1,122 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,373 software developers and data experts.

Best way of storing Tkinter Graphical User Interface Widget option data

440 256MB
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
6 1891
psbasha
440 256MB
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
psbasha
440 256MB
BV/Barton,

Any comments on this.

Thanks
Aug 9 '07 #3
bartonc
6,596 Expert 4TB
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
psbasha
440 256MB
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
6,596 Expert 4TB
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
6,596 Expert 4TB
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

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

Similar topics

53
by: Paul Rubin | last post by:
I've been approached about writing a Windows app which will need a really professional looking GUI. Forget TKinter, this has to actually look good (real artists will be available to get the visual...
1
by: Pekka Niiranen | last post by:
Hi there, after reading TkInter/thread -recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965 I wondered if it was possible to avoid using threads for the following problem: ...
0
by: Svenn Bjerkem | last post by:
Hi, Armed with Programming Python 3rd Edition and Learning Python 2nd edition I try to write an application which I at first thought was simple, at least until I was finished with the GUI and...
3
by: psbasha | last post by:
Hi, I would like to call the same aplication executable with and without Graphical User Interface. Requirement: With Tkinter User interface,user can give the inputs to run the application (...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.