def build(self, tk, parent): self.running = False resources = [ addResource(FileResource("resources/nyancat-%d.png" % i, name="nyancat-%d" % i, type="image/png")) for i in range(0, 12)] img = Image(tk, resource=resources[0]) button = Button(tk, "Start") parent.append(img) parent.append(button) def update_image(i): if self.running: img.resource = resources[i] tk.set_timer(lambda e: update_image((i+1) % 12), 250) def startstop(e): button.text = self.running and "Start" or "Stop" self.running = not self.running update_image(0) button.click = startstop
def build(self, tk, parent): parent.setLayout(Grid(rows=2, columns=4, expand_vertical=True)) self.text = Text(tk) append_button = Button(tk, 'Append') append_button.click = self.append remove_button = Button(tk, 'Remove') remove_button.click = self.remove clear_button = Button(tk, 'Clear') clear_button.click = self.clear parent.append(self.text) parent.append(append_button) parent.append(remove_button) parent.append(clear_button) self.collection = Collection(tk, StaticText) self.collection.extend(['Hello', 'World', 'Bye']) parent.append(self.collection)
def build(self, tk, parent): button = Button(tk, "Click me!") def click(e): button.text = "Click me again!" button.click = click parent.append(button)
def build(self, tk, parent): button = Button(tk, "Click me") self.message = StaticText(tk, "0 clicks") button.click = self.click_handler parent.append(self.message) parent.append(button)
def build(self, tk, parent): self.tk = tk self.lots = [] modal = Button(tk, "Click to open a modal window") nonmodal = Button(tk, "Click to open a non-modal window") alot = Button(tk, "Click to open a lot of windows") self.modal_window = None self.nonmodal_window = None modal.click = self.open_modal nonmodal.click = self.open_nonmodal alot.click = self.open_a_lot parent.append(modal) parent.append(nonmodal) parent.append(alot)
def build(self, tk, parent): parent.setLayout(HBox()) p1 = Panel(tk,width=200, height=200) p2 = Panel(tk, scrolling=True, width=200, height=200) p2.setLayout(VBox()) p1.append(StaticText(tk, "Non-scrolling panel")) p2.append(StaticText(tk, "Scrolling panel")) b = Button(tk, "Click me") p1.append(b) def click(e): p2.append(StaticText(tk, "Line added")) parent.layout() p2.scrollbottom() b.click = click parent.append(p1) parent.append(p2)
def build(self, tk, parent): self.running = False resources = [ addResource(FileResource("resources/nyancat-%d.png" % i, name="nyancat-%d" % i, type="image/png")) for i in range(0, 12) ] img = Image(tk, resource=resources[0]) button = Button(tk, "Start") parent.append(img) parent.append(button) def update_image(i): if self.running: img.resource = resources[i] tk.set_timer(lambda e: update_image((i + 1) % 12), 250) def startstop(e): button.text = self.running and "Start" or "Stop" self.running = not self.running update_image(0) button.click = startstop