2
私はプログラムを作成しようとしています。そのプログラムにはエントリにコードを入力することができ、プログラムはそのコードを実行します。私のexecプログラムが動作していません
Enterキーを押すと、プログラムは前のエントリの下に別のエントリを作成します。
"プログラムの実行"ボタンを押すと、書き込んだコードがすべて実行されます。
from tkinter import *
class Application(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.entry1=Entry(self)
self.entry1.grid(row=0, column=0, sticky=W)
self.bttn1=Button(self, text="Execute code", command=self.execute_code)
self.bttn1.grid(row=1, column=9, sticky=W)
self.rows=0
self.entry1.bind("<Return>", self.down)
def execute_code(self):
self.code=self.entry1.get()
try:
exec(self.code)
except:
print("There is something wrong with this code!")
def down(self,event):
self.rows+=1
entry=Entry(self)
entry.grid(row=self.rows, column=0, sticky=W)
self.code=self.code+"\n"+entry.get()
entry.bind("<Return>", self.down)
root=Tk()
root.title("Executing code")
root.geometry("500x500")
app=Application(root)
問題は、ボタンを押すと、最初のエントリだけが実行されることです。
誰かが自分のコードで何が間違っているか教えてもらえますか?
を単一の複数行のテキストフィールドを使用する方法はありますか? –
それはprint(3)のために実行します、何をしようとしていますか? –
Enterキーを押すとクラッシュします。 –