Editing Russ Python Tips and Techniques
Jump to navigation
Jump to search
Warning: The database has been locked for maintenance, so you will not be able to save your edits right now. You may wish to copy and paste your text into a text file and save it for later.
The system administrator who locked it offered this explanation: restoring Database, Access will be restored shortly
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
= What = | = What = | ||
− | These are Tips and Techniques I have found useful in my Python | + | These are Tips and Techniques I have found useful in my Python programing [[User:Russ_hensel]]. I would be interested in your feedback. Let me know if you think the tip is useful/wrong/something everyone knows. A good set of this material relates to applications with a GUI. They are often not beginner techniques, but neither are they all advanced ones. |
− | Just starting Feb 2017 check history | + | Just starting Feb 2017 check history to see if progress is being made. |
== Ones Still To Be Written == | == Ones Still To Be Written == | ||
− | * when | + | * when devision by 0 is useful |
* code is multiple files - scratch file | * code is multiple files - scratch file | ||
+ | * msg, print( msg ) | ||
* moving to 3.6 use fstrings | * moving to 3.6 use fstrings | ||
− | * example files with functions | + | * example files with functions |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
= Parameters for Applications = | = Parameters for Applications = | ||
Line 160: | Line 68: | ||
</pre> | </pre> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
= Complex Tkinker Windows = | = Complex Tkinker Windows = | ||
− | I found it really easy to get confused in coding Tkinter because it is not a visual interface | + | I found it really easy to get confused in coding Tkinter because it is not a visual interface. So here are some tips: |
− | |||
− | |||
− | |||
− | |||
− | |||
− | So here are some tips: | ||
* I do a sketch of what I want on paper. | * I do a sketch of what I want on paper. | ||
* The GUI is built in a class. | * The GUI is built in a class. | ||
− | * I break the sketch into Tkinter frames each of which will layout into the window in some fairly simple scheme, often the pack layout will work | + | * I break the sketch into Tkinter frames each of which will layout into the window in some fairly simple scheme, often the pack layout will work. |
− | + | * Each individual frame is built in its own subroutine, it takes the parent frame as an argument and returns the frame that it builds. The returned frame is then placed in its parent. | |
− | * Each individual frame is built in its own | + | * References to the widgets are often not needed once the GUI is built, so local variable are often used. For widgets that need references you can use an instance variable of the class, or in some cases it it useful to store them in a dictionary. |
− | * References to the widgets are often not needed once the GUI is built, so local variable are often used | ||
* Building helper classes for either building the widgets, or placing them or both is often useful. | * Building helper classes for either building the widgets, or placing them or both is often useful. | ||
− | * You can see these techniques in GUI class | + | * You can see these techniques in my SmartTerminal GUI class. |
− | |||
= Threading with Tkinker = | = Threading with Tkinker = | ||
Line 348: | Line 171: | ||
<pre> | <pre> | ||
root.attributes("-topmost", True) | root.attributes("-topmost", True) | ||
− | root.attributes("-topmost", False) # if left to True window | + | root.attributes("-topmost", False) # if left to True window alway on top |
</pre> | </pre> | ||
You need to get this to run once after the mainloop is started. You can do this with '''root.after()''' Some details left to you. | You need to get this to run once after the mainloop is started. You can do this with '''root.after()''' Some details left to you. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
[[Category:Python]] | [[Category:Python]] |