Pressable list, using tkinter

Viewed 43

Introduction

Hello out there! Im a highschoolstudent tired of inserting formulas over and over again every time I need to calculate example show angel of fraction for instance. I've written a script that not only calculates this for me, but also prints it on a docx document. With this small program I go the idea of making a formal collection using tkinters as the plugin for a GUI. Ive made some progress, but can't seem to figure out how to make the list "clickable".Help would be greatly appreciated.

Script for interface so far

from tkinter import *

# Defines event and prints widget
def Scankey(event):
    val = event.widget.get()
    print(val)

    if val == '':
        data = list
    else:
        data = []
        for item in list:
            if val.lower() in item.lower():
                data.append(item)

    Update(data)

def Update(data):
    listbox.delete(0, 'end')

    # Makes list of data
    for item in data:
        listbox.insert('end', item)

list = ('Brydningsformel', 'Rydbergformel',)

ws = Tk()

entry = Entry(ws)
entry.pack()
entry.bind('<KeyRelease>', Scankey)

listbox = Listbox(ws)
listbox.pack()
Update(list)

ws.title("Formula")
ws.geometry('500x500+550+200')

ws.mainloop()


Script for calculating angel of fraction

import math
from docx import Document
from docx.shared import Inches



def fb(v1,n1,n2):
    rv1 = math.radians(v1)
    i = math.sin(rv1)*n1/n2
    val = math.degrees(math.asin(i))

    p = document.add_paragraph('Beregning af brydningsvinkel')
    tekst = "Indfaldsvinkel "+ str(v1)+ ", n1= "+ str(n1)+ ", n2= "+ str(n2)
    p = document.add_paragraph(tekst)
    tekst = "Brydningsvinkel "+ str(val)
    p = document.add_paragraph(tekst)
    p = document.add_paragraph()



document = Document()

section = document.sections[0]
header = section.header
header



document.add_heading('Brydningsvinkler', 0)

p = document.add_paragraph('Beregningerne laves ved hjælp af schells lov. Dette har jeg skrevet et pythonscript til at udregne automatisk for mig.')
p = document.add_paragraph()

p.add_run('   def fb(v1,n1,n2):').bold=True
p = document.add_paragraph ()
p.add_run ('   rv1 = math.radians(v1)').bold=True
p = document.add_paragraph ()
p.add_run ('  i = math.sin(rv1)*n1/n2 ' ).bold=True
p = document.add_paragraph ()
p.add_run ('  val = math.degrees(math.asin(i)) ').bold=True
p = document.add_paragraph ()


fb(38,1.33,1)
fb(44,1.33,1.0)
fb(47,1.33,1.0)
fb(48.5,1.33,1.0)
fb(24,1.33,1.0)

paragraph = header.paragraphs[0]
paragraph.text = "Aske Frost"


document.save('demo.docx')

0 Answers
Related