def main(): ComputeStrLayout = [[ sg.Multiline(key='computeStr', background_color='black', text_color='yellow', font="any 30", size=(60, 4)) ]] numsBtLayout = [[ sg.Button(i * 3 + j, size=(4, 2), button_color=('white', 'green'), key=i * 3 + j) for j in range(1, 4) ] for i in range(0, 3)] comBtLayout1= [[sg.Button('0',size=(4,2),key=0),sg.Button('.',size=(4,2),key='.')],\ [sg.Button('(',size=(4,2),key='('),sg.Button('C',size=(4,2),key='C')],\ [sg.Button(')',size=(4,2),key=')'),sg.Button('<=',size=(4,2),key='BackDel')],\ ] comBtLayout2=[\ [sg.Button('+',size=(4,2),key='+'),\ sg.Button('-',size=(4,2),key='-'),\ sg.Button('×',size=(4,2),key='*'),\ sg.Button('÷',size=(4,2),key='/'),\ sg.Button('=',size=(4,2),key='=')]\ ] mainLayout=[[sg.Frame('',ComputeStrLayout)],\ [sg.Frame('',numsBtLayout),\ sg.Column(comBtLayout1)],\ [sg.Frame('',comBtLayout2)],\ ] window = sg.Window('计算器', mainLayout) while True: event, values = window.read() if event in (sg.WIN_CLOSED, 'Exit'): #最后从屏幕上移除 window.close() break if event in list( range(10)) or event in ['.', '(', ')', '+', '-', '*', '/']: window['computeStr'].update(values['computeStr'] + str(event)) elif event == 'C': window['computeStr'].update('') elif event == '=': window['computeStr'].update("%.2f" % computeResult(values['computeStr'])) elif event == 'BackDel': window['computeStr'].update(values['computeStr'][:-1])
SELECTED_DIR, #font=15, background_color=sg.LOOK_AND_FEEL_TABLE[THEME]["BACKGROUND"]) ], [ sg.Frame( "To do", [ [ sg.Listbox( values=todo_list, key="todo_list", size=(WIDTH, HEIGHT), #no_scrollbar=True, #font=("Times New Roman", 12), enable_events=True, #right_click_menu=['&Right', ["Done", "Copy", "Delete"]], background_color='white', ) ], [sg.InputText(key="input_text_todo", size=(25, 1))], ], #font = 15, background_color='orange', element_justification='right', title_color='dark blue', title_location=sg.TITLE_LOCATION_TOP_RIGHT, ) ], [ sg.OK('+', key="add_item"), sg.Button('-', key="Delete-todo"),
sg.Text('All graphic widgets in one window!', size=(30, 1), justification='center', font=("Helvetica", 25), relief=sg.RELIEF_RIDGE) ], [sg.Text('Here is some text.... and a place to enter text')], [sg.InputText('This is my text')], [ sg.Frame(layout=[[ sg.Checkbox('Checkbox', size=(10, 1)), sg.Checkbox('My second checkbox!', default=True) ], [ sg.Radio('My first Radio! ', "RADIO1", default=True, size=(10, 1)), sg.Radio('My second Radio!', "RADIO1") ]], title='Options', title_color='red', relief=sg.RELIEF_SUNKEN, tooltip='Use these to set flags') ], [ sg.Multiline( default_text= 'This is the default Text should you decide not to type anything', size=(35, 3)), sg.Multiline(default_text='A second multi-line', size=(35, 3)) ],
def main(): isGameRestart = True SelBtLayout = [ [sg.Button('不是雷',key='noTagMine')], \ [sg.Button('标注雷',key='tagMine')],\ [sg.Button('点按此格',key='clickCell')],\ [sg.Button('结束本局',key='showAll')],\ [sg.Text('本局成绩:',key='gameResult')], ] MinesLayout = [[ sg.Button('?', size=(4, 2), key=(i, j), pad=(0, 0), button_color=('white', 'green')) for j in range(MAX_COLS) ] for i in range(MAX_ROWS)] mainLayout=[[sg.Frame('雷区', MinesLayout, font='Any 20', title_color='green'),\ sg.Column(SelBtLayout)],\ [sg.Button('重新开始游戏',key='restartGame'),\ sg.Button('退出游戏',key='exitGame')] ] window = sg.Window('扫雷', mainLayout) while isGameRestart: minesInfo = getMineMap() selX = selY = -1 oldX = oldY = -1 isGameContinue = True while True: event, values = window.read() if event in (sg.WIN_CLOSED, 'Exit') or event == 'exitGame': isGameRestart = False #最后从屏幕上移除 window.close() break elif event == 'restartGame': showAllMines(window) for i in range(MAX_ROWS): for j in range(MAX_ROWS): window[(i, j)].update("?", button_color=('white', 'green')) successTags.clear() break if isGameContinue: if event == 'tagMine' and selX >= 0 and selY >= 0 and minesInfo[ selX][selY] == MINE_TAG: successTags.add((selX, selY)) elif event == 'noTagMine' and selX >= 0 and selY >= 0 and minesInfo[ selX][selY] == MINE_TAG: successTags.discard((selX, selY)) if event == 'tagMine' or event == 'noTagMine': if selX >= 0 and selY >= 0: if event == 'tagMine': if window[(selX, selY)].get_text() == '?': window[(selX, selY)].update('*') else: if window[(selX, selY)].get_text() == '*': window[(selX, selY)].update('?', button_color=('white', 'green')) elif event == 'clickCell': window[(selX, selY)].update(minesInfo[selX][selY], button_color=('yellow', 'blue')) if window[(selX, selY)].get_text() == MINE_TAG: window[(selX, selY)].update(minesInfo[selX][selY], button_color=('red', 'black')) elif event == 'showAll': showAllMines(window) isGameContinue = False else: if oldX >= 0 and oldY >= 0 and window[ (selX, selY)].get_text() != MINE_TAG: window[(oldX, oldY)].update(button_color=('white', 'green')) selX = event[0] selY = event[1] if window[(selX, selY)].get_text() != MINE_TAG: window[event].update(button_color=('Green', 'black')) oldX = selX oldY = selY