gpt-4-0613· OpenAI
Arena Human Preference 55K
Code a simple calculator using python's Tkinter.
- User
Code a simple calculator using python's Tkinter.
- Assistant
Sure, here's a simple Python script that creates a GUI calculator using Tkinter:
from tkinter import * def click(event): text = event.widget.cget("text") if text == "=": try: result = str(eval(screen.get())) screen.set(result) except Exception as e: screen.set("Error") elif text == "C": screen.set("") else: screen.set(screen.get() + text) root = Tk() root.geometry("300x400") root.title("Simple Calculator") screen = StringVar() entry = Entry(root, textvar = screen, font="lucida 20 bold") entry.pack(fill=X, ipadx=8, pady=10, padx=10) button_frame = Frame(root) button_frame.pack() list_of_buttons = ['7', '8', '9', '/', '4', '5', '6', '*', '1', '2', '3', '-', '0', '.', '=', '+'] i = 0 for btn in list_of_buttons: button = Button(button_frame, text=btn, font='lucida 15 bold') button.grid(row=int(i/4), column=i%4, padx=3, pady=3) button.bind("<Button-1>", click) i += 1 clear_button = Button(button_frame, text="C", font='lucida 15 bold') clear_button.grid(row=int(i/4), column=i%4, padx=3, pady=3) clear_button.bind("<Button-1>", click) root.mainloop()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.