KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
from Tkinter import * window = Tk() frame=Frame(window) frame.pack() text_area = Text(frame) text_area.pack() text1 = text_area.get('0.0',END) def cipher(data): As,Ts,Cs,Gs, = 0,0,0,0 for x in data: if 'A' == x: As+=1 elif x == 'T': Ts+=1 elif x =='C': Cs+=1 elif x == 'G': Gs+=1 result = StringVar() result.set('Num As: '+str(As)+' Num of Ts: '+str(Ts)+' Num Cs: '+str(Cs)+' Num Gs: '+str(Gs)) label=Label(window,textvariable=result) label.pack() button=Button(window,text="Count", command= cipher(text1)) button.pack() window.mainloop() What I'm trying to accomplish is entering a string of 'AAAATTTCA' in my Text widget and have the label return the number of occurrences. With the entry 'ATC' the function would return Num As: 1 Num Ts: 1 Num Cs: 1 Num Gs: 0. What I don't understand is why I am not reading in my text_area correctly.
Tags (comma-separated)
Save Edits
Cancel