Re: [問題] 有沒有可以插入在程式中的互動模式?
有沒有你說的工具我並不清楚
不知道下面的程式碼是否能達到你想要的功能
from Tkinter import *
class Interface:
def __init__(self,master=None):
if master is None:
master=Tk()
frame1=Frame(master)
frame1.pack(expand=1,fill="both")
self.entry=entry=Text(frame1,height=1)
entry.focus_force()
entry.pack(side="top",fill="both")
entry.bind("<Return>",self.act)
def act(self,evt):
print '----------------------'
exec self.entry.get('0.0',END) in locals(),globals()
print '----------------------'
def interact():
root=Tk()
Interface(root)
root.mainloop()
a=5
b=6
if a==5:
c=6
interact()
print s
當程式碼執行到interact時,會出現一個視窗
你可以在那個視窗輸入python的程式碼(你按ENTER執行指令)
在上面例子你輸入print a
他就會執行你輸入的指令
所以會輸出a的值5
同樣地,你如果在輸入框裡輸入s=6的話
執行到print s時就會印出6
不然的話會出現變數未定義
這個程式應該只能用在你沒有使用tkinter
如果你有用tkinter的話需要改一下程式
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.172.223.56
→
07/26 01:04, , 1F
07/26 01:04, 1F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
Python 近期熱門文章
PTT數位生活區 即時熱門文章