Tags » Tkinter » Page 2

Simple Python calculator using Tkinter

This is a code for simple python calculator written by me

#learnpythoncoding

from tkinter import*
root=Tk()
root.geometry("250x150")
root.title("CALCULATOR")

no1 = IntVar()
no2 = IntVar()

label1=Label(text="Enter 1st No.")
label1.grid(row=1)
label2=Label(text="Enter 2nd No.")
label2.grid(row=2)

entry1=Entry(root, textvariable=no1)
entry1.grid(row=1,column=1)
entry2=Entry(root, textvariable=no2)
entry2.grid(row=2,column=1)
txt =Text(root,width=25,height=2, wrap=WORD)
txt.grid(row=0,column=1)

def add():
    add = (no1.get() + no2.get())
    txt.insert(0.0,add)
def sub():
    sub = (no1.get() - no2.get())
    txt.insert(0.0,sub)
def mul():
    mul = (no1.get() * no2.get())
    txt.insert(0.0,mul)
def div():
    div = (no1.get() / no2.get())
    txt.insert(0.0,div)

b1=Button(root,text="add",command=add)
b1.grid(row=5,column=0)
b2=Button(root,text="sub",command=sub)
b2.grid(row=5,column=1)
b3=Button(root,text="mul",command=mul)
b3.grid(row=6,column=0)
b4=Button(root,text="div",command=div)
b4.grid(row=6,column=1)
root.mainloop()
                      
#blog

Pi with Neopixels/Simulated Neopixels

Neopixels are addressable full-colour RGB LEDs that come in a variety of different arrangements. Ranging from single LEDs, to matrix arrays and a variety of sewable components that can be used on wearable products. 827 more words

Auto Photo Colorizer

Auto Photo Colourizer

Colorization Or Colourization?

I have just finished writing a beta version of Auto Photo Colourizer. I wasn’t sure whether to use the U.S or British spelling of the word… 1,095 more words

Tkinter

Tkinter TreeView - Enable Sorting upon Clicking Column Headings

The below code snippet can help you achieve the Sorting Option on Treeview Column Headings in Tkinter in both ascending and descending order.

columns = ("Student","Course","Last Session")

tv = Treeview(popup, show='headings', columns=columns,height=25)

def treeview_sort_column(tv, col, reverse):
    l = [(tv.set(k, col), k) for k in tv.get_children('')]
    l.sort(reverse=reverse)

    # rearrange items in sorted positions
    for index, (val, k) in enumerate(l):
        tv.move(k, '', index)

    # reverse sort next time
    tv.heading(col, command=lambda _col=col: treeview_sort_column(tv, _col, not reverse))

for col in columns:
    tv.heading(col, text=col,command=lambda _col=col: treeview_sort_column(tv, _col, False))
tv.pack()

 

ModuleNotFoundError: No module named 'babel.numbers'

Traceback (most recent call last):
File "tkinter/__init__.py", line 1705, in __call__
File "script.py", line 726, in
File "script.py", line 536, in calendar
File "tkcalendar/calendar_.py", line 211, in __init__…
90 more words

Get Pyinstaller to import ttkthemes

Operating System: Mac OS

The below solution worked perfectly

Step 1
pyinstaller script_name.py --hidden-import ttkthemes

Step 2
Copy the ttkthemes folder from venv/lib/python3.x/site-packages folder in your distribution folder (dist)