Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Adding Tkinter GUI #698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions gui/xy_vacuum_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Gui(VacuumEnvironment):
dirty, clean or can have a wall. The user can change these at each step.
"""
xi, yi = (0, 0)
perceptible_distance = 1

def __init__(self, root, width=7, height=7, elements=['D', 'W']):
super().__init__(width, height)
Expand Down Expand Up @@ -122,6 +123,20 @@ def update_env(self):
self.step()
xf, yf = agt.location

def reset_env(self, agt):
"""Resets the GUI environment to the intial state."""
self.read_env()
for i, btn_row in enumerate(self.buttons):
for j, btn in enumerate(btn_row):
if (i != 0 and i != len(self.buttons) - 1) and (j != 0 and j != len(btn_row) - 1):
if self.some_things_at((i, j)):
for thing in self.list_things_at((i, j)):
self.delete_thing(thing)
btn.config(text='', state='normal')
self.add_thing(agt, location=(3, 3))
self.buttons[3][3].config(
text='A', state='disabled', disabledforeground='black')


def XYReflexAgentProgram(percept):
"""The modified SimpleReflexAgentProgram for the GUI environment."""
Expand Down Expand Up @@ -151,18 +166,19 @@ def __init__(self, program=None):
self.direction = Direction("up")


# TODO: Check the coordinate system.
# TODO:
# Check the coordinate system.
# Give manual choice for agent's location.
def main():
"""The main function."""
root = Tk()
root.title("Vacuum Environment")
root.geometry("420x440")
root.resizable(0, 0)
frame = Frame(root, bg='black')
# create a reset button
# reset_button = Button(frame, text='Reset', height=2,
# width=6, padx=2, pady=2, command=None)
# reset_button.pack(side='left')
reset_button = Button(frame, text='Reset', height=2,
width=6, padx=2, pady=2)
reset_button.pack(side='left')
next_button = Button(frame, text='Next', height=2,
width=6, padx=2, pady=2)
next_button.pack(side='left')
Expand All @@ -171,6 +187,7 @@ def main():
agt = XYReflexAgent(program=XYReflexAgentProgram)
env.add_thing(agt, location=(3, 3))
next_button.config(command=env.update_env)
reset_button.config(command=lambda: env.reset_env(agt))
root.mainloop()


Expand Down