71216

Seven segment display in Tkinter

Question:

I am trying to create a GUI using Tkinter with Python 2.7. This must have a seven segment display or something similar to dynamically display values in accordance with a variable. Is there any way to create a seven segment display apart from a manual graphical design (that would slow down the entire system)?

Answer1:

I don't know what you mean by 'maunal graphical design' but here is a single hex diget display designed to be easily upgraded to more digits. It will not slow the system noticeably.

'''Seven segment display of hex digits.''' import tkinter as tk root = tk.Tk() screen = tk.Canvas(root) screen.grid() # Order 7 segments clockwise from top left, with crossbar last. # Coordinates of each segment are (x0, y0, x1, y1) # given as offsets from top left measured in segment lengths. offsets = ( (0, 0, 1, 0), # top (1, 0, 1, 1), # upper right (1, 1, 1, 2), # lower right (0, 2, 1, 2), # bottom (0, 1, 0, 2), # lower left (0, 0, 0, 1), # upper left (0, 1, 1, 1), # middle ) # Segments used for each digit; 0, 1 = off, on. digits = ( (1, 1, 1, 1, 1, 1, 0), # 0 (0, 1, 1, 0, 0, 0, 0), # 1 (1, 1, 0, 1, 1, 0, 1), # 2 (1, 1, 1, 1, 0, 0, 1), # 3 (0, 1, 1, 0, 0, 1, 1), # 4 (1, 0, 1, 1, 0, 1, 1), # 5 (1, 0, 1, 1, 1, 1, 1), # 6 (1, 1, 1, 0, 0, 0, 0), # 7 (1, 1, 1, 1, 1, 1, 1), # 8 (1, 1, 1, 1, 0, 1, 1), # 9 (1, 1, 1, 0, 1, 1, 1), # 10=A (0, 0, 1, 1, 1, 1, 1), # 11=b (1, 0, 0, 1, 1, 1, 0), # 12=C (0, 1, 1, 1, 1, 0, 1), # 13=d (1, 0, 0, 1, 1, 1, 1), # 14=E (1, 0, 0, 0, 1, 1, 1), # 15=F ) class Digit: def __init__(self, canvas, *, x=10, y=10, length=20, width=3): self.canvas = canvas l = length self.segs = [] for x0, y0, x1, y1 in offsets: self.segs.append(canvas.create_line( x + x0*l, y + y0*l, x + x1*l, y + y1*l, width=width, state = 'hidden')) def show(self, num): for iid, on in zip(self.segs, digits[num]): self.canvas.itemconfigure(iid, state = 'normal' if on else 'hidden') dig = Digit(screen) n = 0 def update(): global n dig.show(n) n = (n+1) % 16 root.after(1000, update) root.after(1000, update) root.mainloop()

Recommend

  • Best datastore for storing 20,000 items to be queried by UISearchBar
  • Upgrading to jQuery 1.7 and changes to the event object
  • Python3 ImportError: No module named '_tkinter' on Ubuntu
  • Showing Tkinter window larger than desktop
  • Return values of Tkinter text entry, close GUI
  • Python. Error using animation.FuncAnimation
  • Threads and Tkinter not working together
  • how to assign hotkeys?
  • Sending a variable with a button-command (python 3.3 / tkinter) [duplicate]
  • Passing extra arguments with Tkinter Bindings
  • Python 2.x or 3.x on a Chromebook
  • Highlighting a clicked line in an unfocused Tkinter text widget
  • Status of shift and caps lock in Python
  • starttls on node.js > 0.4.0
  • How to use Spring Integration 5 with Spring Boot 1.5.x
  • How to show matplotlib plot from a figure object
  • How to do “(df1 & not df2)” dataframe merge in pandas?
  • How do I write to registers in hardware using Python?
  • Tkinter nested mainloop
  • Matplotlib: Custom colormap with three colors [duplicate]
  • why isn't the natural height of a Frame updated immediately?
  • Visual Basic 6 on Win7 64bit: Will developed program run on 32-bit Win OS?
  • remove unicode characters but keep all special and English characters with preg_replace
  • How do you create a Fuseki SPARQL server using the Apache Jena Java API?
  • What is the use of a session store?
  • apply a javascript function to draggable copy
  • Python cosine function precision [duplicate]
  • Aptana 3 remove bundle (jquery)
  • netsh acl setting (need alternative method - registry settings?)
  • Calculate time difference in hh:mm:ss with simple javascript/jquery
  • Sails.js/waterline: Executing waterline queries in toJSON function of a model?
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • Redux, normalised entities and lodash merge
  • Do create extension work in single-user mode in postgres?
  • Why winpcap requires both .lib and .dll to run?
  • Return words with double consecutive letters
  • Transpose CSV data with awk (pivot transformation)
  • Python: how to group similar lists together in a list of lists?
  • Buffer size for converting unsigned long to string
  • Busy indicator not showing up in wpf window [duplicate]