2012-04-04 8 views
1

私はOSX 10.6.8、Python 2.7.2をTkinterバージョン8.5で使用していますが、Python、Tkinter、IDLEのインストールはきれいになりましたPython 3.2のインストール。私は、MITのOpen CourseWare(クレジットではない)から設定された "RSS Feed Filter"の問題に取り組んでいます。これには、書き留めていないいくつかのモジュールと理解できないモジュールが含まれています。そのうちの1つ(news_guiモジュール)は、デバッグ方法がわからない未処理の例外をスローしています。Python Tkinter未処理例外スレッド開始<function main_thread at ...>

# 6.00 Problem Set 5 
# RSS Feed Filter 


import pdb 
#pdb.set_trace() 


import feedparser 
import string 
import time 
from project_util import translate_html 
from news_gui import Popup 

################################# 
########## CODE OMITTED ######### 
################################# 

import thread 

def main_thread(p): 
    # A sample trigger list - you'll replace 
    # this with something more configurable in Problem 11 
    t1 = SubjectTrigger("Obama") 
    t2 = SummaryTrigger("MIT") 
    t3 = PhraseTrigger("Supreme Court") 
    t4 = OrTrigger(t2, t3) 
    triggerlist = [t1, t4] 

    # TODO: Problem 11 
    # After implementing readTriggerConfig, uncomment this line 
    #triggerlist = readTriggerConfig("triggers.txt") 

    guidShown = [] 

    while True: 
     print "Polling..." 

     # Get stories from Google's Top Stories RSS news feed 
     stories = process("http://news.google.com/?output=rss") 
     # Get stories from Yahoo's Top Stories RSS news feed 
     stories.extend(process("http://rss.news.yahoo.com/rss/topstories")) 

     # Only select stories we're interested in 
     stories = filter_stories(stories, triggerlist) 

     # Don't print a story if we have already printed it before 
     newstories = [] 
     for story in stories: 
      if story.get_guid() not in guidShown: 
       newstories.append(story) 

     for story in newstories: 
      guidShown.append(story.get_guid()) 
      p.newWindow(story) 

     print "Sleeping..." 
     time.sleep(SLEEPTIME) 

SLEEPTIME = 60 #seconds -- how often we poll 
if __name__ == '__main__': 
    print '1' 
    p = Popup() 
    print '2' 
    thread.start_new_thread(main_thread, (p,)) 
    print '3' 
    p.start() 
    print '4' 

(下から2番目)p.start()ラインは、ここでは、news_guiモジュールからのポップアップを呼び出してそのコードは次のとおりです。

import Tkinter 
import time 

print help(Tkinter.Tk) 

#root = Tk() 
#root.withdraw() 

import pdb 


# The Popup class 
class Popup: 
    def __init__(self): 
     print 'Popup init' 

     self.root = Tkinter.Tk() 
     self.root.withdraw() 

     """ 
    self.root.mainloop() 
     def drawALot(): 
      self.root = Tk() 
      self.root.withdraw() 
      self.root.mainloop() 
     thread.start_new_thread(drawALot,()) 
    """ 
    def start(self): 
     print 'Popup start' 
     pdb.set_trace() 
     self.root.mainloop() 

    def _makeTheWindow(self, item): 
     """ 
     Private method that does the actual window drawing 
     """ 
     print 'Popup _makeTheWindow' 
     root = Tkinter.Toplevel() 
     root.wm_title("News Alert") 

     w = root.winfo_screenwidth()/20 
     h = root.winfo_screenheight()/4 

     title = Tkinter.Text(root, padx=5, pady=5, height=3, wrap=Tkinter.WORD, bg="white") 
     title.tag_config("title", foreground="black", font=("helvetica", 12, "bold")) 
     title.tag_config("subject", foreground="black", font=("helvetica", 12, "bold")) 
     title.insert(Tkinter.INSERT, "Title: %s" % item.get_title(), "title") 
     title.insert(Tkinter.INSERT, "\nSubject: ", "subject") 
     title.insert(Tkinter.INSERT, item.get_subject().rstrip(), "subject")  

     title.config(state=Tkinter.DISABLED, relief = Tkinter.FLAT) 
     title.grid(sticky=Tkinter.W+Tkinter.E) 

     print '_makeTheWindow .5' 

     summary = Tkinter.Text(root, padx=10, pady=5, height=15, wrap=Tkinter.WORD, bg="white") 
     summary.tag_config("text", foreground="black", font=("helvetica", 12)) 
     summary.insert(Tkinter.INSERT, item.get_summary().lstrip(), "text") 

     summary.config(state=Tkinter.DISABLED, relief = Tkinter.FLAT) 
     summary.grid(sticky=Tkinter.W+Tkinter.E) 

     link = Tkinter.Text(root, padx=5, pady=5, height=4, bg="white") 
     link.tag_config("url", foreground="blue", font=("helvetica", 10, "bold")) 
     link.insert(Tkinter.INSERT, item.get_link(), "url") 

     link.config(state=Tkinter.DISABLED, relief=Tkinter.FLAT) 
     link.grid(sticky=Tkinter.W+Tkinter.E) 

     print '_makeTheWindow end' 

    def newWindow(self, item): 
     """ 
     Displays a popup with the contents of the NewsStory newsitem 
     """ 
     print 'Popup newWindow' 
     self.root.after(0, self._makeTheWindow, item) 

私はここで有効にPDBで実行すると、私の出力であります:

None 
1 
Popup init 
2 
3Polling... 

Popup start 
> /Users/**********/Desktop/Learn/CS Stuffs/6-00sc-spring-2011/6-00sc-spring-2011/contents/unit-2/lecture-12-introduction-to-simulation-and-random-walks/ps5/news_gui.py(31)start() 
-> self.root.mainloop() 
(Pdb) s 
--Call--Unhandled exception in thread started by 
<function main_thread at 0x1026ed848>> 
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py(1015)mainloop() 
-> def mainloop(self, n=0): 
(Pdb) s 
> /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py(1017)mainloop() 
-> self.tk.mainloop(n) 
(Pdb) s 

これがハングします。これはスレッディングやTkinterと関係があると言えますが、私は次に何をすべきか分かりません。

編集:Windows 7仮想マシンにPython 2.7.2をインストールするだけで問題が発生します。

+0

OS X 10.6以降用のpython.org 2.7.2 64ビット/ 32ビットインストーラを使用している場合は、ActiveState Tcl/Tk 8.5もインストールしてください。 OS X 10.6のアップル社が提供するTcl/Tk 8.5はかなりバグがあります(10.7バージョンは優れていますが、まだいくつかの重要なバグがあります)。 http://www.python.org/download/mac/tcltk/ –

+0

を参照してください*私はPythonのクリーンアップ中にインストールしたものだと信じていますが、二重チェックする良い方法はありますか? –

+0

ファイル '/ Library/Frameworks/Tcl.framework/tclConfig.sh'を見てください。存在し、 'TCL_VERSION = '8.5''と 'TCL_PATCH_LEVEL = '。11' ' - これが最新バージョンです。 'otool -L $(python2.7 -c" import _tkinter; print(_tkinter .__ file __) ")'出力には '/Library/Frameworks/Tcl.frameworkが含まれていなければなりません。/Versions/8.5/Tcl'を参照してください。 –

答えて

1

私は解決策の何かを見つけましたが、私はそれの全体的な適応性について話すことはできません。これは、他の人が同様のピクルスに役立つかもしれませんが、知識が豊富な方はチャイムで助けてください。

http://tkinter.unpythonic.net/wiki/mtTkinterからmtTkinterをダウンロードしました。 "修正されたコードは、スレッド外のTkinter呼び出しをインターセプトし、メインループで定期的に実行される 'after'イベントによって読み取られるキューを介してそれらをマーシャリングします。"

正確にはわかりませんが、問題は修正されました。

関連する問題