Esempio n. 1
0
animals = [
    'anteater.gif', 'ardvark.gif', 'armadillo.gif', 'llama.gif', 'tapir.gif'
]


def press(btn):
    animal = random.choice(animals)

    if btn == "animal1":
        win.setImage("animal1", animal)
    elif btn == "animal2":
        win.setImage("animal2", animal)
    elif btn == "EXIT":
        win.stop()


win = gui("SNAP")

win.setGeom("500x400")
win.setBg("black")

win.addLabel("lb1", "Let's play snap!", 0, 0, 2)
win.setLabelBg("lb1", "red")

win.addImage("animal1", "ardvark.gif", 1, 0)
win.addImage("animal2", "anteater.gif", 1, 1)

win.addButtons(["animal1", "animal2", "EXIT"], press, 2, 0, 2)

win.go()
Esempio n. 2
0

def press(btn):
    red = win.getEntry("Red")
    green = win.getEntry("Green")
    blue = win.getEntry("Blue")
    rgb = "#" + red + green + blue
    print(rgb)
    win.setBg(rgb)


def zoom(btn):
    print(win.getScale("scl"))
    win.zoomImage("img", win.getScale("scl"))


# create the GUI and start it
win = gui("Hexadecimal Colours")

#win.setFont(16)
win.addLabelEntry("Red")
win.addLabelEntry("Green")
win.addLabelEntry("Blue")
win.addButton("Submit", press)
win.addScale("scl")
win.setScaleRange("scl", -5, 5)
win.setScaleCommand("scl", zoom)
win.addImage("img", "../resources/8ball.gif")

win.go()
Esempio n. 3
0
      win.setLabel("dob", dob)

def press(btn):
      print(btn)
      print(data)
      print(pos)
      global pos
      if btn == "Back" and pos > 1:
            pos -= 1
            updateScreen()

      elif btn == "Forward" and pos < maxLen:
            pos += 1
            updateScreen()

win = gui("FaceBook")

win.setBg("Blue")
win.setFont(16)

win.addButton("Back", press, 0, 0, 0)
win.addLabel("lbl", "FaceBook", 0, 1, 0)
win.addButton("Forward", press, 0, 2, 0)

win.addLabel("lb2", "Name",1,0,1)
win.addLabel("name", "xxx",1,1,2)

win.addLabel("lb3", "Gender",2,0,1)
win.addLabel("gender", "xxx",2,1,2)

win.addLabel("lb4", "DoB",3,0,1)
Esempio n. 4
0
def press(btn):
      if btn == "Page A": showPageA()
      elif btn == "Page B": showPageB()
      elif btn == "Page C": showPageC()

# function to make page A
def showPageA():
      win.removeAllWidgets() # this will remove any existing widgets
      win.setBg("Red")
      win.addLabel("l1", "Page A")
      win.addButton("Page B", press)

# function to make page B
def showPageB():
      win.removeAllWidgets()
      win.setBg("Green")
      win.addLabel("l2", "Page B")
      win.addButton("Page C", press)

# function to make page C
def showPageC():
      win.removeAllWidgets()
      win.setBg("Blue")
      win.addLabel("l3", "Page C")
      win.addButton("Page A", press)

# create the GUI, show page A, and GO!
win = gui ( "Hello" )
showPageA()
win.go ( )
Esempio n. 5
0
numRows = 20


def getData():
    rows = []
    for loop in range(numRows):
        rows.append(getRanRow(5))
    return rows


def getRanRow(size=10):
    cells = []
    for loop in range(size):
        cells.append(str(random.randint(1, 9)) * 10)
    return cells


# function to handle button press
def press(name):
    win.updateGrid('g1', getData())


# create the window
win = gui("Grid!")
win.addLabel("l1", "hhhhhhhhhaaaaaaaaaaaaaaaaahhhhhhhhhhh")

win.addGrid('g1', getData())
win.addButton("Rand", press)

win.go()
Esempio n. 6
0
# import the library
from rwbatools import gui
win = gui("Translate")

trans = {"lol": "laugh out loud"}
canAdd = False


def press(name):
    word = win.getEntry("Word")
    if word in trans:
        ans = trans[word]
    else:
        ans = "Unknown..."

    win.setLabel("l1", ans)


def newV(name):
    global trans
    trans[win.getEntry("nw")] = win.getEntry("nv")


def checkAdd(name):
    if canAdd: disableAdd()
    else: enableAdd()


def disableAdd():
    global canAdd
    canAdd = False
Esempio n. 7
0
            win.stop()


def tools(name):
    if name == "Background":
        col = win.colourBox()
        if col is not None:
            win.setTextAreaBg("win", col)
            win.setBg(col)
    elif name == "Foreground":
        col = win.colourBox()
        if col is not None:
            win.setTextAreaFg("win", col)
    elif name == "Font +":
        win.increaseLabelFont()
    elif name == "Font -":
        win.decreaseLabelFont()


win = gui("Editor :: untitled.txt")

win.addMenuList("File", ["New", "Open...", "Save", "-", "Exit"], menus)
win.addToolbar(["Background", "Foreground", "Font +", "Font -"], tools)

win.addScrolledTextArea("win")
win.setTextAreaBg("win", "green")
win.setBg("green")
win.setTextAreaFocus("win")

win.go()
Esempio n. 8
0
    #      else:
    #            win.setLabelBg("status", "red")
    #            win.setLabel("status", "Server DOWN")
    #            win.disableEntry("Msg")
    #
    msg = net.getMessage()
    if msg is not None and len(msg) > 0:
        win.addListItem("messages", "Received: " + msg)
        count = count + 1
        win.setTitle("Chat: " + str(count))


# create and configure the GUI
net = net(9999)

win = gui("Chat")
win.setFont(16)
win.setBg("yellow")

win.addRadioButton("Server", "Client", 0, 0)
win.addRadioButton("Server", "Server", 0, 1)

win.addEntry("ip", colspan=2)
win.setEntry("ip", str(net.getIPAddress()))
win.addListBox("messages", colspan=2)
win.addLabelEntry("Msg", colspan=2)
win.setEntryWidth("Msg", 15)
win.setEntryFunction("Msg", press)
win.setFocus("Msg")
win.addEmptyLabel("status", colspan=2)
win.setPollTime(500)
Esempio n. 9
0
        win.setLabel("amount", str(conv) + " " + to)
    except:
        win.errorBox("Error", "Invalid amount, make sure you enter a number.")


def updateRate(name):
    global currencies
    currencies[name] = win.numBox("New Rate",
                                  "Enter the new exchange rate for: " + name)


# first load the currencies
loadFile(fileName)

# create the GUI and start it
win = gui("Currency")
win.setFont(16)

win.addLabel("title", "Currency Converter", 0, 0, 4)

win.addEntry("amount", 1, 0)
win.setEntryWidth("amount", 5)
win.setFocus("amount")
win.setEntryFunc("amount", press)

win.addOptionBox("from", currencies.keys(), 1, 1)
win.addLabel("to", "To:", 1, 2)
win.addOptionBox("to", currencies.keys(), 1, 3)

win.addButton("Convert", press, 1, 4)
win.addLabel("amount", "0", 2, 2, 2)
Esempio n. 10
0
def updateRate(name):
    global currencies
    currencies[name] = win.numBox("New Rate",
                                  "Enter the new exchange rate for: " + name)


def newCurrency(name):
    global currencies
    newC = win.textBox("New Currency", "Enter a new currency")
    if newC is not None: currencies[newC] = 0


# create the GUI
loadFile(fileName)
win = gui("Currency Converter")
win.setStopFunction(stop)
win.addMenuList("Rates", currencies.keys(), updateRate)
win.addLabel("l1", "Currency Converter", 0, 0, 5)

win.addLabel("l2", "Amount", 1, 0)
win.addLabel("l3", "From:", 1, 1)
win.addLabel("l4", "To:", 1, 2)
win.addLabel("l5", "Result:", 1, 3)

win.addEntry("Amount", 2, 0)
win.setEntryWidth("Amount", 5)
win.addOptionBox("source", currencies.keys(), 2, 1)
win.addOptionBox("target", currencies.keys(), 2, 2)
win.addLabel("result", 0.0, 2, 3)
win.addButton("Convert", press, 2, 4)
Esempio n. 11
0
from rwbatools import gui


def press(btn):  # the title of the button will be received as a parameter
    print(btn)


app = gui()
app.setFont(20)
app.addButton("One", press)  # 3 buttons, each calling the same function
app.addButton("Two", press)
app.addButton("Three", press)
app.go()