def modal_dialog(): #global dlog ### dlog = ModalDialog(title="Spanish Inquisition", size=(200, 140)) dlog.place(Label(text="Surprise!!!"), left=20, top=20) field = TextField() dlog.place(field, left=20, top=60, right=-20) field.become_target() dlog.default_button = DefaultButton() dlog.cancel_button = CancelButton() dlog.place(dlog.default_button, right=-20, bottom=-20) dlog.place(dlog.cancel_button, left=20, bottom=-20) dlog.center() result = dlog.present() say("Result =", result) dlog.destroy()
from GUI.StdButtons import DefaultButton, CancelButton from testing import say class TestDialog(Dialog): def ok(self): say("OK") def cancel(self): say("Cancel") dlog = TestDialog(width=250) lbl = Label(text="Eject the tomato?") ok_btn = DefaultButton() cancel_btn = CancelButton() dlog.place(lbl, left=20, top=20) dlog.place(ok_btn, left=20, top=lbl + 20) dlog.place(cancel_btn, right=-20, top=lbl + 20) dlog.height = ok_btn.bounds[3] + 20 dlog.show() instructions = """ There should be a non-modal dialog with two buttons in 'default' and 'cancel' styles. The window should be movable but not resizable. Messages should be printed when the buttons are pressed (although they should not dismiss the dialog). Return and Enter should activate the OK button, and Escape should activate the Cancel button.
def _create_buttons(self, yes_label, no_label, cancel_label): self.yes_button = DefaultButton(title=yes_label, action=self.yes) self.no_button = CancelButton(title=no_label, action=self.no) self.other_button = Button(title=cancel_label, action=self.other) self.default_button = self.yes_button self.cancel_button = self.other_button
def _create_buttons(self, yes_label, no_label): self.yes_button = DefaultButton(title=yes_label, action=self.yes) self.no_button = CancelButton(title=no_label, action=self.no)