34 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for HiHe
Member Avatar for martineau
1
21K
Member Avatar for vegaseat
Member Avatar for TrustyTony

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.

Member Avatar for Gribouillis
0
5K
Member Avatar for vegaseat

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.

Member Avatar for toyota_1
0
12K
Member Avatar for vegaseat

If you have a long message to display in a large readable font, then this little Tkinter GUI toolkit code might help.

Member Avatar for Mohamed_65
1
4K
Member Avatar for vegaseat
Member Avatar for BustACode

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 …

0
2K
Member Avatar for vegaseat

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 …

Member Avatar for vegaseat
4
2K
Member Avatar for DragonMastur

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 …

0
686
Member Avatar for vegaseat

Sometimes it's easier to pick an image from the internet to display in your Python Tkinter GUI toolit program.

Member Avatar for vegaseat
1
5K
Member Avatar for sneekula

You can accesss the clipboard simply by using the Tkinter GUI toolkit that comes with your Python installation.

Member Avatar for TrustyTony
1
14K
Member Avatar for vegaseat

If you draw a series of close spaced shapes your eyes get fooled to see Moire patterns. Here is one example of this.

2
2K
Member Avatar for vegaseat

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.

2
1K
Member Avatar for vegaseat
Member Avatar for vegaseat

Shows you how to create multiple Tkinter buttons in a loop, each with its own name, label and command response.

Member Avatar for CodingCabbage
2
1K
Member Avatar for vegaseat

The code sample shows how to get an image from the internet and show it in a Tkinter label widget.

Member Avatar for Nils_1
4
2K
Member Avatar for vegaseat

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().

Member Avatar for vegaseat
3
4K
Member Avatar for vegaseat

This Python snippet shows how to control a VPython visual 3D sphere with Tkinter GUI toolkit button clicks.

4
3K
Member Avatar for vegaseat

A short code to show you how you can download and display an image from the internet on Python's Tkinter GUI toolkit.

3
307
Member Avatar for vegaseat

A closer look at the Tkinter GUI toolkit Toplevel Window and how to lift and lower it respective to other windows.

0
6K
Member Avatar for TrustyTony

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: …

0
764
Member Avatar for TrustyTony

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.

0
496
Member Avatar for TrustyTony

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: …

0
2K
Member Avatar for TrustyTony

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.

Member Avatar for TrustyTony
2
2K
Member Avatar for woooee

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 …

Member Avatar for TrustyTony
5
550
Member Avatar for TrustyTony

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 …

Member Avatar for Enalicho
0
10K
Member Avatar for TrustyTony

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 …

Member Avatar for TrustyTony
0
1K
Member Avatar for TrustyTony

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).

0
819
Member Avatar for TrustyTony

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.

Member Avatar for e-papa
0
744
Member Avatar for Beat_Slayer

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. …

Member Avatar for gleam.uahmed
0
1K

The End.