473,729 Members | 2,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best way of storing Tkinter Graphical User Interface Widget option data

440 Contributor
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 1912
psbasha
440 Contributor
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 Contributor
BV/Barton,

Any comments on this.

Thanks
Aug 9 '07 #3
bartonc
6,596 Recognized Expert Expert
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 Contributor
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 Recognized Expert Expert
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 Recognized Expert Expert
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
6446
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 stuff right). Assuming I write in Python, what's the best toolkit to use? Some cost in implementation pain is tolerable if the finished interface looks better as a result. It would be nice if the toolkit runs on multiple platforms rather than...
1
2251
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: I have script started from W2K console that normally prints ascii messages to the screen. However, I have command line "debug" -flag that might cause printing
0
1425
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 then wanted to start putting some data into it. As you will see, the program is not yet finished but I post what I have so far.
3
2171
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 ( Interactive). Instead user will have this inputs in the file and it will be read by the batch utility or exe for the application For example:
0
8917
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.