Jump to content

Ajuda com GUI


JoaoRodrigues

Recommended Posts

# File: dialog1.py

from Tkinter import *
from get4pubmed import *

import string, os, sys, time

try:
from Bio import Medline
except:
print "Import error, could not run: from Bio import Medline !!!"
print "\n"

try:
from Bio import PubMed
except:
print "Import error , could not run : from Bio import PubMed"
print "\n"

# Functions

def get_searchterm_ids(search_term):
"""Search PubMed for a search term, return the corresponding document tile and abstract and write them into a file each"""
start = time.clock()	
pmid = search_term

search = PubMed.search_for(search_term)

# access Medline through a dictionary interface that returns PubMed Records
rec_parser = Medline.RecordParser()
medline_dict = PubMed.Dictionary(parser = rec_parser)

print "Total articles found : ", len(search)
end = time.clock()
print "Total Time Spent:",end-start,"seconds"

# write each retrieved article into a file

for id in search[0:]:
	start = time.clock()
	cur_record = medline_dict[id]
	PMID = str(id)
	TI = string.rstrip(cur_record.title)
	AB = cur_record.abstract

	out_filename = str(PMID) +'.txt'
	o_file = open(out_filename,'w')

	o_file.write("PMID: ")
	o_file.write(PMID)
	o_file.write("\nLINK: ")
	o_file.write('http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pubmed&Cmd=ShowDetailView&TermToSearch='+PMID+'&ordinalpos=1&itool=EntrezSystem2.PEntrez.Pubmed.Pubmed_ResultsPanel.Pubmed_RVDocSum')
	o_file.write("\nPUBMED TITLE: ")

	o_file.write(TI)
	o_file.write('\n')
	o_file.write('\nABSTRACT: ')
	o_file.write(AB)
	o_file.write('\n')
	end = time.clock()
	print "Time Spent Archiving:",end-start,"seconds"

# Main

class MyDialog:

    def __init__(self, parent):

        top = self.top = Toplevel(parent)

        Label(top, text="Search Term").pack()

        self.e = Entry(top)
        self.e.pack(padx=5)

        b = Button(top, text="Search!", command=self.ok)
        b.pack(pady=5)

    def ok(self):
    	print "Searching ..."
    	search_term = self.e.get()	
self.top.destroy()

root = Tk()
Button(root).pack()
root.update()

d = MyDialog(root)

root.wait_window(d.top)


if __name__ == '__main__':
get_searchterm_ids(search_term)

Traceback (most recent call last):
  File "<stdin>", line 94, in <module>
NameError: name 'search_term' is not defined

Help

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.