September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -0,0 +1,17 @@
|
|||
∇ WindowedApplication
|
||||
|
||||
⍝ define a form with a label and a button
|
||||
'Frm'⎕WC'Form' 'Clicks' (40 35) (10 15)
|
||||
'Lbl'Frm.⎕WC'Label' 'There have been no clicks yet.' (10 10)
|
||||
'Btn'Frm.⎕WC'Button' 'Click Me' (35 35) (25 25) ('Event' 'Select' 'Click')
|
||||
|
||||
⍝ callback function
|
||||
Frm.Clicks←0
|
||||
Frm.Click←{
|
||||
Clicks+←1
|
||||
p0←(1+Clicks=1)⊃'have' 'has'
|
||||
p1←(1+Clicks=1)⊃'clicks' 'click'
|
||||
Lbl.Value←'There ',p0,' been ',(⍕Clicks),' ',p1,'.'
|
||||
}
|
||||
|
||||
∇
|
||||
|
|
@ -1,49 +1,41 @@
|
|||
import forms.
|
||||
import extensions.
|
||||
import forms;
|
||||
import extensions;
|
||||
|
||||
class Window
|
||||
public class MainWindow : SDIDialog
|
||||
{
|
||||
object form.
|
||||
object lblClicks.
|
||||
object btmClickMe.
|
||||
Label lblClicks;
|
||||
Button btmClickMe;
|
||||
|
||||
//Store how much clicks the user doed
|
||||
object clicksCount.
|
||||
int clicksCount;
|
||||
|
||||
constructor new
|
||||
[
|
||||
form := SDIDialog new.
|
||||
lblClicks := Label new.
|
||||
btmClickMe := Button new.
|
||||
constructor new()
|
||||
<= new()
|
||||
{
|
||||
lblClicks := new Label();
|
||||
btmClickMe := new Button();
|
||||
|
||||
clicksCount := 0.
|
||||
clicksCount := 0;
|
||||
self
|
||||
.appendControl(lblClicks)
|
||||
.appendControl(btmClickMe);
|
||||
|
||||
form controls;
|
||||
append:lblClicks;
|
||||
append:btmClickMe.
|
||||
self.Caption := "Rosseta Code";
|
||||
self.setRegion(100, 100, 160, 80);
|
||||
|
||||
form
|
||||
set caption:"Rosseta Code";
|
||||
set x:100 y:100;
|
||||
set width:160 height:80.
|
||||
lblClicks.Caption := "Clicks: 0";
|
||||
lblClicks.setRegion(10, 2, 160, 20);
|
||||
|
||||
lblClicks
|
||||
set x:10 y:2;
|
||||
set width:160 height:20;
|
||||
set caption:"Clicks: 0".
|
||||
btmClickMe.Caption := "Click me";
|
||||
btmClickMe.setRegion(7, 20, 140, 30);
|
||||
|
||||
btmClickMe
|
||||
set x:7 y:20;
|
||||
set width:140 height:30;
|
||||
set caption:"Click me";
|
||||
set onClick(:args)[ $self $onButtonClick ]
|
||||
]
|
||||
btmClickMe.onClick := (args){ self.onButtonClick(); };
|
||||
}
|
||||
|
||||
$onButtonClick
|
||||
[
|
||||
clicksCount := clicksCount + 1.
|
||||
lblClicks set caption("Clicks: " + clicksCount literal).
|
||||
]
|
||||
private onButtonClick()
|
||||
{
|
||||
clicksCount := clicksCount + 1;
|
||||
|
||||
dispatch => form.
|
||||
lblClicks.Caption := "Clicks: " + clicksCount.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,29 @@
|
|||
from Tkinter import Tk, Label, Button
|
||||
from functools import partial
|
||||
|
||||
def update_label():
|
||||
global n
|
||||
n += 1
|
||||
l["text"] = "Number of clicks: %d" % n
|
||||
import tkinter as tk
|
||||
|
||||
w = Tk()
|
||||
n = 0
|
||||
l = Label(w, text="There have been no clicks yet")
|
||||
l.pack()
|
||||
Button(w, text="click me", command=update_label).pack()
|
||||
w.mainloop()
|
||||
|
||||
def on_click(label: tk.Label,
|
||||
counter: tk.IntVar) -> None:
|
||||
counter.set(counter.get() + 1)
|
||||
label["text"] = f"Number of clicks: {counter.get()}"
|
||||
|
||||
|
||||
def main():
|
||||
window = tk.Tk()
|
||||
label = tk.Label(master=window,
|
||||
text="There have been no clicks yet")
|
||||
label.pack()
|
||||
counter = tk.IntVar()
|
||||
update_counter = partial(on_click,
|
||||
label=label,
|
||||
counter=counter)
|
||||
button = tk.Button(master=window,
|
||||
text="click me",
|
||||
command=update_counter)
|
||||
button.pack()
|
||||
window.mainloop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
#!/usr/bin/env python
|
||||
from Tkinter import Button, Frame, Label, Pack
|
||||
import tkinter as tk
|
||||
|
||||
class ClickCounter(Frame):
|
||||
def click(self):
|
||||
self.count += 1
|
||||
self.label['text'] = 'Number of clicks: %d' % self.count
|
||||
|
||||
def createWidgets(self):
|
||||
self.label = Label(self, text='here have been no clicks yet')
|
||||
self.label.pack()
|
||||
self.button = Button(self, text='click me', command=self.click)
|
||||
self.button.pack()
|
||||
|
||||
class ClickCounter(tk.Frame):
|
||||
def __init__(self, master=None):
|
||||
Frame.__init__(self, master)
|
||||
Pack.config(self)
|
||||
self.createWidgets()
|
||||
super().__init__(master)
|
||||
tk.Pack.config(self)
|
||||
self.label = tk.Label(self, text='There have been no clicks yet')
|
||||
self.label.pack()
|
||||
self.button = tk.Button(self,
|
||||
text='click me',
|
||||
command=self.click)
|
||||
self.button.pack()
|
||||
self.count = 0
|
||||
|
||||
if __name__=="__main__":
|
||||
def click(self):
|
||||
self.count += 1
|
||||
self.label['text'] = f'Number of clicks: {self.count}'
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ClickCounter().mainloop()
|
||||
|
|
|
|||
|
|
@ -1,20 +1,36 @@
|
|||
import sys
|
||||
from qt import *
|
||||
from functools import partial
|
||||
from itertools import count
|
||||
|
||||
def update_label():
|
||||
global i
|
||||
i += 1
|
||||
lbl.setText("Number of clicks: %i" % i)
|
||||
from PyQt5.QtWidgets import (QApplication,
|
||||
QLabel,
|
||||
QPushButton,
|
||||
QWidget)
|
||||
from PyQt5.QtCore import QRect
|
||||
|
||||
i = 0
|
||||
app = QApplication(sys.argv)
|
||||
win = QWidget()
|
||||
win.resize(200, 100)
|
||||
lbl = QLabel("There have been no clicks yet", win)
|
||||
lbl.setGeometry(0, 15, 200, 25)
|
||||
btn = QPushButton("click me", win)
|
||||
btn.setGeometry(50, 50, 100, 25)
|
||||
btn.connect(btn, SIGNAL("clicked()"), update_label)
|
||||
win.show()
|
||||
app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))
|
||||
app.exec_loop()
|
||||
LABEL_GEOMETRY = QRect(0, 15, 200, 25)
|
||||
BUTTON_GEOMETRY = QRect(50, 50, 100, 25)
|
||||
|
||||
|
||||
def on_click(_, label, counter=count(1)):
|
||||
label.setText(f"Number of clicks: {next(counter)}")
|
||||
|
||||
|
||||
def main():
|
||||
application = QApplication([])
|
||||
window = QWidget()
|
||||
label = QLabel(text="There have been no clicks yet",
|
||||
parent=window)
|
||||
label.setGeometry(LABEL_GEOMETRY)
|
||||
button = QPushButton(text="click me",
|
||||
parent=window)
|
||||
button.setGeometry(BUTTON_GEOMETRY)
|
||||
update_counter = partial(on_click,
|
||||
label=label)
|
||||
button.clicked.connect(update_counter)
|
||||
window.show()
|
||||
application.lastWindowClosed.connect(window.close)
|
||||
application.exec_()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
|||
|
|
@ -1,28 +1,35 @@
|
|||
import wx
|
||||
|
||||
class MyApp(wx.App):
|
||||
def click(self, event):
|
||||
self.count += 1
|
||||
self.label.SetLabel("Count: %d" % self.count)
|
||||
|
||||
def OnInit(self):
|
||||
frame = wx.Frame(None, wx.ID_ANY, "Hello from wxPython")
|
||||
self.count = 0
|
||||
self.button = wx.Button(frame, wx.ID_ANY, "Click me!")
|
||||
self.label = wx.StaticText(frame, wx.ID_ANY, "Count: 0")
|
||||
self.Bind(wx.EVT_BUTTON, self.click, self.button)
|
||||
class ClickCounter(wx.Frame):
|
||||
def __init__(self):
|
||||
super().__init__(parent=None)
|
||||
self.count = 0
|
||||
self.button = wx.Button(parent=self,
|
||||
label="Click me!")
|
||||
self.label = wx.StaticText(parent=self,
|
||||
label="There have been no clicks yet")
|
||||
self.Bind(event=wx.EVT_BUTTON,
|
||||
handler=self.click,
|
||||
source=self.button)
|
||||
|
||||
self.sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.sizer.Add(self.button, True, wx.EXPAND)
|
||||
self.sizer.Add(self.label, True, wx.EXPAND)
|
||||
frame.SetSizer(self.sizer)
|
||||
frame.SetAutoLayout(True)
|
||||
self.sizer.Fit(frame)
|
||||
self.sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.sizer.Add(window=self.button,
|
||||
proportion=1,
|
||||
flag=wx.EXPAND)
|
||||
self.sizer.Add(window=self.label,
|
||||
proportion=1,
|
||||
flag=wx.EXPAND)
|
||||
self.SetSizer(self.sizer)
|
||||
self.sizer.Fit(self)
|
||||
|
||||
frame.Show(True)
|
||||
def click(self, _):
|
||||
self.count += 1
|
||||
self.label.SetLabel(f"Count: {self.count}")
|
||||
|
||||
self.SetTopWindow(frame)
|
||||
return True
|
||||
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
if __name__ == '__main__':
|
||||
app = wx.App()
|
||||
frame = ClickCounter()
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue