I updated your code a bit. Now it is running without error but since you are setting your move_choice_S
to True
, it is writing to text
only S
on each button press.
EDIT: I updated move_choice_S
parts. Since you defined move_choice_S
in global scope, you don't need use self.
to use/reach it. You can use it by move_choice_S
or as @FabienAndre said, you can define it in __init__
.
-option sticky
needs its argument as string. So I changed those.
insert
needs at least two arguments. First is index and the second is what is going to be inserted.
I imported using import xxx
form, so I changed all tkinter
items according to that but it's just a habit. You don't have to use this import
form.
import Tkinter as tk
class Application(tk.Frame):
def __init__(self, master):
""" init the frame """
tk.Frame.__init__(self)
self.grid()
self.create_widgets()
def create_widgets(self):
self.bttn15 = tk.Button(self, text = "OK", command = self.update_moves)
self.bttn15.grid(row = 14, column = 4, sticky = "W")
# message
self.box_txt = tk.Text(self, width = 65, height = 25, wrap = "word")
self.box_txt.grid(row = 15, column = 0, columnspan = 5, sticky = "W")
def update_moves(self):
moves = ""
if move_choice_S.get():
moves = "S"
self.box_txt.insert(0.0, moves + "\n")
# Main
root = tk.Tk()
move_choice_S = tk.BooleanVar()
move_choice_S.set(True)
move_choice_S.get()
root.title("Maltparser1.0_demo")
root.geometry("900x700")
app = Application(root)
root.mainloop()