好的,所以我绝对是Python的新手,所以请忍受我的无知。
我正在与PyCharm一起编写练习互动功能。
基本上,我想生成一个带有两个文本输入字段和两个按钮的交互式窗口。
一个按钮(QUIT)将退出应用程序,另一个按钮(运行DNA扫描)将启动它。
第一个文本输入字段采用DNA序列(例如:atgcagatgac),另一个采用较小的“搜索”序列(例如:cag)。
计划是,一旦填写了两个文本字段,按下“运行DNA序列”将启动DNA_scan()函数 - 我编写并在单独调用时工作正常。
问题是,'QUIT'按钮按照应有的方式工作,但'Run DNA Sequence'按钮什么都不做。
提前致谢!
这是我现在的代码:
import tkinter
from tkinter import *
class Application(Frame):
def DNA_scan(self): #this is a search function I wrote myself - it works fine on its own
dataf = str(input())
s = str(input())
datar = dataf[::-1]
print('Your data input contains ' + str((dataf.count(s))) + ' instances of your search input on the FORWARD strand:')
data = dataf.lower()
b = s.lower()
c = b.upper()
print(data.replace(b,c))
datar = datar.lower()
i = 0
reverse = ''
s = s.lower()
for ch in datar:
if ch == 'a':
ch = 't'
reverse = reverse + ch
i = i+1
elif ch == 't':
ch = 'a'
i = i+1
reverse = reverse + ch
elif ch == 'c':
ch = 'g'
i = i+1
reverse = reverse + ch
elif ch == 'g':
ch = 'c'
i = i+1
reverse = reverse + ch
print('And, your data input contains ' + str((reverse.count(s))) + ' instances of your search input on the REVERSE strand:')
a = reverse.lower()
b = s.lower()
c = b.upper()
print(a.replace(b,c))
def createWidgets(self):
root.title("DNA scan")
Label (text="Please enter your DNA sequence:").pack(side=TOP,padx=10,pady=10)
dataf = Entry(root, width=10).pack(side=TOP,padx=10,pady=10)
Label (text="Please enter your search sequence:").pack(side=TOP,padx=10,pady=10)
s = Entry(root, width=10).pack(side=TOP,padx=10,pady=10)
self.button = Button(root,text="Run DNA scan",command=self.DNA_scan)
self.button.pack()
self.QUIT = Button(self)
self.QUIT["text"] = "QUIT"
self.QUIT["fg"] = "red"
self.QUIT["command"] = self.quit
self.QUIT.pack({"side": "left"})
def __init__(self, master=None):
Frame.__init__(self, master)
self.filename = None
self.pack()
self.createWidgets()
root = Tk()
root.title("DiNA")
root.quit()
app = Application(master=root)
app.mainloop()