34 Reusable Code Snippet Topics
Remove Filter
|
|
A simple way to create a toggle button for the Tkinter Python GUI toolkit. |
|
Shows how to create a basic slide show with the Python Tkinter GUI toolkit. |
|
This is one small snippet of after event usage. You could express if you find this kind of simple code to be usefull as snippet. Notice also vegaseat's sticky message threads in begining of Python forum in addition to code snippets. |
|
The Tkinter GUI toolkit comes with a scrolled text widget that is called ScrolledText. To get access to it you have to import it separately. It allows you to display large amounts of text in a small space. |
|
If you have a long message to display in a large readable font, then this little Tkinter GUI toolkit code might help. |
|
This simple key logger shows any character/special key when pressed. |
|
I found that one can use dictionaries to hold Tkinter widget config and display parameters. This then permits one to have these dictionaries elsewhere in the code for easy modification instead of buried within the code for each widget. I particularly like to place these dictionaries toward the top of … |
|
This is the updated version of the Tiny Tkinter Calculator. It has more power, since you can type in functions contained in the Python math module then press the equals key. You can then move the result into memory for other calculations. The code is written in OOP class style … |
|
I needed a calculator and I didn't want to use google since my internet is slow. So I made one! Here it is. Working with it is simple. Use the number and operation keys("c" for clear, "p" for pi, and "s" for sqrt) as well as the return and enter … |
|
Sometimes it's easier to pick an image from the internet to display in your Python Tkinter GUI toolit program. |
|
You can accesss the clipboard simply by using the Tkinter GUI toolkit that comes with your Python installation. |
|
If you draw a series of close spaced shapes your eyes get fooled to see Moire patterns. Here is one example of this. |
|
An example how to use Tkinter's OptionMenu() as a combobox to allow one year to be selected from an option list of let's say the past 15 years. |
|
A Tkinter image button that toggles between an up and down button image. |
|
Shows you how to create multiple Tkinter buttons in a loop, each with its own name, label and command response. |
|
The code sample shows how to get an image from the internet and show it in a Tkinter label widget. |
|
Simple code to show you how to display an image from a Web URL using the Tkinter Python GUI toolkit, the Python Image Library (PIL) and the data_stream created with io.BytesIO(). |
|
This Python snippet shows how to control a VPython visual 3D sphere with Tkinter GUI toolkit button clicks. |
|
A short code to show you how you can download and display an image from the internet on Python's Tkinter GUI toolkit. |
|
A closer look at the Tkinter GUI toolkit Toplevel Window and how to lift and lower it respective to other windows. |
|
We can run Python2 script in most simple cases if we just use the 2to3.py script found in recent Python versions: F:\Python27\Tools\Scripts>copy \test\output_window_tk.py \test\output_window_tk2.py 1 tiedosto(a) on kopioitu. F:\Python27\Tools\Scripts>2to3.py -w \test\output_window_tk.py RefactoringTool: Skipping implicit fixer: buffer RefactoringTool: Skipping implicit fixer: idioms RefactoringTool: Skipping implicit fixer: set_literal RefactoringTool: Skipping implicit fixer: … |
|
This code is based on code from series of programs [URL="http://www.ferg.org/thinking_in_tkinter/"]'Thinking in tkinter'[/URL] This code is not perfect, especially it does not recognize key release when mouse moves out of button area during push. Leave event could also be captured for that to stop the event in that case. |
|
I post here the code for histogram using the turtle graphics module, which I posted long time ago in discussion thread. For more special graphs there exist other fancier options, but this tkinter based routine can function in most standard installations of Python. Example data.txt, like mentioned in module docstring: … |
|
This is similar to earlier posts in DaniWeb by vegaseat, but it demonstrates getkey with withdrawn tkinter, restart inside object by re-calling it's __init__ method. |
|
From a thread on another forum, I wondered how difficult it would be to create a Tic-Tac-Toe game that could not be beaten. Since it is easiest if the computer goes first and chooses the center square, this code implements that portion. The logic is fairly simple; occupy the center … |
|
Inspired by password entry discussions, I did this simple entry. You must of course find safe way to store the passwords, for example hashlib ([url]http://stackoverflow.com/questions/4820043/basics-of-python-encryption-w-hashlib-sha1[/url]) or [URL="https://www.dlitz.net/software/pycrypto/"]PyCrypto[/URL] and replace the simplistic example match for real life usage. The print at line 23 is just to check the attempts and to … |
|
Here is Mandelbrot set viewer in Tkinter and modules for shedskining (included compiled modules for windows in the zip file): [CODE]# mandelsh.py def mandel(real, imag, max_iterations=20): '''determines if a point is in the Mandelbrot set based on deciding if, after a maximum allowed number of iterations, the absolute value of … |
|
My not OO version of timer for work and pause time (but it does use attributes for functions, which are objects, to avoid global declarations in functions). |
|
Here version of TicTacToe demo [URL="http://www.daniweb.com/software-development/python/threads/357974/1526474#post1526474"]code by wooeee[/URL] with packing style, which is more familiar for me. Also fixed indents and made it run also with Python 3. |
|
Simple script for image transparency. Someone asked one some time ago, and i had other but for a different system, and decided to write a Python/PIL version. The value of the color used as transparent is the value of the pixel at position (0, 0). You can adjust tolerance value. … |
The End.