コード例 #1
0
    def createButton(self):
        CRIT = 'crit'
        WARN = 'warn'
        REGU = 'regu'
        SIGNS = {
            'do not enter': CRIT,
            'railroad crossing': WARN,
            '55\nspeed limit': REGU,
            'wrong way': CRIT,
            'merging traffic': WARN,
            'one way': REGU,
        }
        critCB = lambda: showerror('Error', 'Error Button Pressed')
        warnCB = lambda: showwarning('Warning', 'Warning Button Pressed')
        infoCB = lambda: showinfo('Info', 'Info Button Pressed')
        self.quitButton = Button(self,
                                 text='Quit',
                                 bg='red',
                                 fg='white',
                                 command=self.quit)
        self.quitButton.pack()
        # 调用mybutton时,会调用Button类,并将self作为第一个参数传递
        mybutton = pto(Button, self)
        # 二阶偏函数,根据不同类型
        CritButton = pto(mybutton, command=critCB, bg='white', fg='red')
        WarnButton = pto(mybutton, command=warnCB, bg='blue')
        ReguButton = pto(mybutton, command=infoCB, bg='white')

        for eachSign in SIGNS:
            signType = SIGNS[eachSign]
            cmd = '%sButton(text=%r%s).pack(fill=X, expand=1)' % (
                signType.title(), eachSign,
                '.upper()' if signType == CRIT else '.title()')
            eval(cmd)
コード例 #2
0
ファイル: ch19_gui.py プロジェクト: rexnie/my_python
def roadSigns():
    WARN = 'warn'
    CRIT = 'crit'
    REGU = 'regu'

    SIGNS = {
'do not enter'      : CRIT,
'railroad crossing' : WARN,
'55\nspeed limit'   : REGU,
'wrong way'         : CRIT,
'merging traffic'   : WARN,
'one way'           : REGU,
}
    critCB = lambda: showerror('Error', 'Error Button Pressed!')
    warnCB = lambda: showwarning('Warning', 'Warning Button Pressed!')
    infoCB = lambda: showinfo('Info', 'Info Button Pressed!')

    top = Tk()
    top.title('Road Signs')
    Button(top, text='QUIT', command=top.quit, bg='red', fg='white').pack()

    MyButton = pto(Button, top)
    CritButton = pto(MyButton, command=critCB, bg='white', fg='red')
    WarnButton = pto(MyButton, command=warnCB, bg='goldenrod1')
    ReguButton = pto(MyButton, command=infoCB, bg='white')

    for eachSign in SIGNS:
        signType = SIGNS[eachSign]
        cmd = '%sButton(text=%r%s).pack(fill=X, expand=True)' % (
        signType.title(), eachSign, '.upper()' if signType == CRIT else '.title()')
        eval(cmd)
    top.mainloop()
コード例 #3
0
def roadSigns():
    WARN = 'warn'
    CRIT = 'crit'
    REGU = 'regu'

    SIGNS = {
        'do not enter': CRIT,
        'railroad crossing': WARN,
        '55\nspeed limit': REGU,
        'wrong way': CRIT,
        'merging traffic': WARN,
        'one way': REGU,
    }
    critCB = lambda: showerror('Error', 'Error Button Pressed!')
    warnCB = lambda: showwarning('Warning', 'Warning Button Pressed!')
    infoCB = lambda: showinfo('Info', 'Info Button Pressed!')

    top = Tk()
    top.title('Road Signs')
    Button(top, text='QUIT', command=top.quit, bg='red', fg='white').pack()

    MyButton = pto(Button, top)
    CritButton = pto(MyButton, command=critCB, bg='white', fg='red')
    WarnButton = pto(MyButton, command=warnCB, bg='goldenrod1')
    ReguButton = pto(MyButton, command=infoCB, bg='white')

    for eachSign in SIGNS:
        signType = SIGNS[eachSign]
        cmd = '%sButton(text=%r%s).pack(fill=X, expand=True)' % (
            signType.title(), eachSign,
            '.upper()' if signType == CRIT else '.title()')
        eval(cmd)
    top.mainloop()
コード例 #4
0
def BuildStreetSignsGUI():
    WARN = 'warn'  # Warning
    CRIT = 'crit'  # Critical message
    REGU = 'regu'  # Regular message

    SIGNS = {
        'Do Not Enter': CRIT,
        'Railroad Crossing': WARN,
        '65 Speed Limit': REGU,
        'Wrong Way': CRIT,
        'Merging Traffic': WARN,
        'One Way': REGU,
    }

    critCB = lambda: showerror('Error', 'Error Button Pressed')
    warnCB = lambda: showwarning('Warning', 'Warning Button Pressed')
    infoCB = lambda: showinfo('Info', 'Info Button Pressed')

    top = Tk()
    top.title('Road Signs')
    quit = Button(top, text='QUIT', command=top.quit, bg='red', fg='white')
    quit.pack()

    MyButton = pto(Button, top)
    CritButton = pto(MyButton, command=critCB, bg='white', fg='red')
    WarnButton = pto(MyButton, command=warnCB, bg='goldenrod1')
    ReguButton = pto(MyButton, command=infoCB, bg='white')

    for eachSign in SIGNS:
        signType = SIGNS[eachSign]
        cmd = '%sButton(text=%r%s).pack(fill=X, expand=True)' % (
            signType.title(), eachSign,
            '.upper()' if signType == CRIT else '.title()')
        eval(cmd)
コード例 #5
0
def test1():
    WARN = "warn"
    CRIT = "crit"
    REGU = "regu"

    SIGNS = {
        "do not enter": CRIT,
        "railroad crossing": WARN,
        "55\nspeed limit": REGU,
        "wrong way": CRIT,
        "merging traffic": WARN,
        "one way": REGU,
    }

    critCB = lambda: messagebox.showerror("Error", "Error Button Pressed!")
    warnCB = lambda: messagebox.showwarning("Warning",
                                            "Warning Button Pressed!")
    infoCB = lambda: messagebox.showinfo("Info", "Info Button Pressed!")

    top = tkinter.Tk()
    top.title("Road Signs")
    tkinter.Button(top, text="QUIT", command=top.quit, bg="red",
                   fg="white").pack()

    MyButton = pto(tkinter.Button, top)
    CritButton = pto(MyButton, command=critCB, bg="white", fg="red")
    WarnButton = pto(MyButton, command=warnCB, bg="white")
    ReguButton = pto(MyButton, command=infoCB, bg="white")

    for eachSign in SIGNS:
        signType = SIGNS[eachSign]
        cmd = "%sButton(text=%r%s).pack(fill=tkinter.X, expand=True)" % (
            signType.title(), eachSign,
            ".upper()" if signType == CRIT else ".title()")
        eval(cmd)

    top.mainloop()
    pass
コード例 #6
0
SIGNS = { 
'do not enter': CRIT, 
'railroad crossing': WARN,
'55\nspeed limit': REGU,
'wrong way': CRIT, 
'merging traffic': WARN,
'one way': REGU, 
} 

critCB = lambda: showerror('Error', 'Error Button Pressed!') 
warnCB = lambda: showwarning('Warning', 'Warning Button Pressed!') 
infoCB = lambda: showinfo('Info', 'Info Button Pressed!') 

top = Tk() 
top.title('Road Signs') 
Button(top, text='QUIT', command=top.quit, 
bg='red', fg='white').pack() 

MyButton = pto(Button, top) 
CritButton = pto(MyButton, command=critCB, bg='white', fg='red') 
WarnButton = pto(MyButton, command=warnCB, bg='goldenrod1') 
ReguButton = pto(MyButton, command=infoCB, bg='white') 

for eachSign in SIGNS: 
    signType = SIGNS[eachSign] 
    cmd = '%sButton(text=%r%s).pack(fill=X, expand=True)' % ( signType.title(), eachSign, '.upper()' if signType == CRIT else '.title()') 
    eval(cmd) 

top.mainloop() 
コード例 #7
0
ファイル: pfaGui2.py プロジェクト: lufb/code
CRIT = "crit"
REGU = "regu"

signs = {"do not enter:":CRIT,
         "railroad crossing":WARN,
        "55\nspeed limit":REGU,
        "wront way":CRIT,
        "merging traffic":WARN,
        "one way":REGU,
         }

critCB = lambda: messagebox.showerror("Error", "Error button Pressed!")
warnCB = lambda: messagebox.showerror("Warning", "Warnig Button Pressed!")
infoCB = lambda: messagebox.showinfo("Info", "Info button Pressed!")

top = Tk()
top.title("Road signs")
Button(top, text = 'Quit', command = top.quit, bg = "red", fg = "white").pack()

mybotton = pto(Button, top)
CritButton = pto(mybotton, command = critCB)
WarnButton = pto(mybotton, command = warnCB)
ReguButton = pto(mybotton, command = infoCB)

for each in signs:
    signtype = signs[each]
    cmd = "%sButton(text=%r%s).pack(fill=X, expand=True)" % (signtype.title(), each,".upper()" if signs == CRIT else ".title()")
    eval(cmd)
    
top.mainloop()
コード例 #8
0
SIGNS = {
    'do not enter': CRIT,
    'railroad crossing': WARN,
    '55\nspeed limit': REGU,
    'wrong way': CRIT,
    'merging traffic': WARN,
    'one way': REGU,
}

critCB = lambda: showerror('Error', 'Error Button Pressed')
warnCB = lambda: showwarning('Warning', 'Warning Button Pressed')
infoCB = lambda: showinfo('Info', 'Info Button Pressed')

top = Tk()
top.title('Road  Signs')
Button(top, text='Quit', command=top.quit, bg='red', fg='white').pack()

myButton = pto(Button, top)
CritButton = pto(myButton, command=critCB, bg='white', fg='red')
WarnButton = pto(myButton, command=warnCB, bg='green')
ReguButton = pto(myButton, command=infoCB, bg='white')

for eachSign in SIGNS:
    signType = SIGNS[eachSign]
    #print(signType, signType.title())
    cmd = '%sButton(text=%r%s).pack(fill=X, expand=True)' % (signType.title(
    ), eachSign, '.upper()' if signType == CRIT else '.title()')
    eval(cmd)
top.mainloop()
コード例 #9
0
ファイル: pfaGui2.py プロジェクト: lufb/code
signs = {
    "do not enter:": CRIT,
    "railroad crossing": WARN,
    "55\nspeed limit": REGU,
    "wront way": CRIT,
    "merging traffic": WARN,
    "one way": REGU,
}

critCB = lambda: messagebox.showerror("Error", "Error button Pressed!")
warnCB = lambda: messagebox.showerror("Warning", "Warnig Button Pressed!")
infoCB = lambda: messagebox.showinfo("Info", "Info button Pressed!")

top = Tk()
top.title("Road signs")
Button(top, text='Quit', command=top.quit, bg="red", fg="white").pack()

mybotton = pto(Button, top)
CritButton = pto(mybotton, command=critCB)
WarnButton = pto(mybotton, command=warnCB)
ReguButton = pto(mybotton, command=infoCB)

for each in signs:
    signtype = signs[each]
    cmd = "%sButton(text=%r%s).pack(fill=X, expand=True)" % (
        signtype.title(), each, ".upper()" if signs == CRIT else ".title()")
    eval(cmd)

top.mainloop()
コード例 #10
0
ファイル: pfaGUI2.py プロジェクト: roytest001/PythonCode
from Tkinter import Tk, Button, X
from tkMessageBox import showinfo, showwarning, showerror

WARN = 'warn'
CRIT = 'crit'
REGU = 'regu'

SIGNS = {'do not enter': CRIT, 'railroad crossing': WARN, '55\nspeed limit': REGU,
         'wrong way': CRIT, 'merging traffic': WARN, 'one way': REGU, }

critCB = lambda: showerror('Error', 'Error Button Pressed!')
warnCB = lambda: showwarning('Warning', 'Warning Button Pressed!')
infoCB = lambda: showinfo('Info', 'Info Button Pressed!')

top = Tk()
top.title('Road Signs')
Button(top, text='QUIT', command=top.quit(), bg='green', fg='blue').pack()

MyButton = pto(Button, top)
CritButton = pto(MyButton, command=critCB, bg='yellow', fg='pick')
WarnButton = pto(MyButton, command=warnCB, bg='goldenrod1')
CritButton = pto(MyButton, command=infoCB, bg='white')

for eachSign in SIGNS:
    signType = SIGNS[eachSign]
    cmd = '%s Button(text=%r%s).pack(fill=X, expand=True)' % (
    signType.title(), eachSign, '.upper()' if signType == CRIT else '.title()')
    eval(cmd)

top.mainloop()
コード例 #11
0
ファイル: pfaGUI.py プロジェクト: zzzzzwyu/CPAP
REGU = "regu"

SIGNS = {
    "do not enter": CRIT,
    "railroad crossing": WARN,
    "55\nspeed limit": REGU,
    "merging traffic": WARN,
    "wrong way": CRIT,
    "one way": REGU,
}

critCB = lambda: showerror("Error", "Error Button Pressed!")
warnCB = lambda: showwarning("Warning", "Warning Button Pressed!")
reguCB = lambda: showinfo("Info", "Info Button Pressed")

top = Tk()
top.title("Road Signs")
Button(top, text="QUIT", command=top.quit, bg="red", fg="white").pack()

MyButton = pto(Button, top)
CritButton = pto(MyButton, command=critCB, bg="white", fg="red")
WarnButton = pto(MyButton, command=warnCB, bg="goldenrod1")
ReguButton = pto(MyButton, command=reguCB, bg="white")

for each_sign in SIGNS:
    sign_type = SIGNS[each_sign]
    cmd = "%sButton(text=%r%s).pack(fill=X, expand=True)" % (sign_type.title(
    ), each_sign, '.upper()' if sign_type == CRIT else '.title()')
    eval(cmd)
top.mainloop()
コード例 #12
0
ファイル: d3p3.py プロジェクト: iamKarthikBK/SeriousPython
    return a * a


f = lambda a: a * a
print(square(5))
print(f(6))

# dont seem to be of great use right
# Lets see in the next example


# let us get the other guy out of the way
# partial functions are function created on top of function with parameters half filled
# EXAMPLE
def func(a, b, c, d):
    x = a + b + c + d
    return x
    # whatever that means


# Now this supecomplex function has under certain conditions a=1,b=2,c=4 which only d changing
from functools import partial as pto
# I can now define a new func easy_func with these parameters fixed
easy_func = pto(func, 1, 2, 4)
print(func(1, 2, 3, 4))
print(easy_func(3))
# thats all boss nothing extra ordinary
# BUT WHY THESE TWO CONCEPTS RANDOMLY IN THE MIDDLE OF SOMETHING
# The next example will help you understand and thene maybe we do a bit of functional programming
# and iterators and generators and this new thing calles ups from the apc standard
    "wrong way": CRIT,
    "merging traffic": WARN,
    "one way": REGU,
}

#创建回调函数,在按动按钮时调用
critCB = lambda: showerror("Error", "Error Button Pressed!")
warnCB = lambda: showwarning("Warning", "Warning Button Pressed!")
infoCB = lambda: showinfo("Info", "Info Button Pressed!")

#创建顶层窗口并创建一个quit按钮
top = Tk()
top.title("Road Signs")
Button(top, text="QUIT", command=top.quit, bg="red", fg="white").pack()

#使用二阶偏函数进行模板化
MyButton = pto(Button, top)  #一阶模板化Button类和根窗口
CritButton = pto(MyButton, command=critCB, bg="white", fg="red")
WarnButton = pto(MyButton, command=warnCB, bg="goldenrod1")
ReguButton = pto(MyButton, command=infoCB, bg="white")

#格式化创建命令字符串并通过eval函数实例化
for eachSign in SIGNS:
    signType = SIGNS[eachSign]
    cmd = "%sButton(text=%r%s).pack(fill=X, expand=True)" % (signType.title(
    ), eachSign, ".upper()" if signType == CRIT else ".title()")
    eval(cmd)

#启动主事件循环
top.mainloop()
コード例 #14
0
		'one way': REGU
	}

	crit_CB = lambda: showerror('Error', 'Error Button Pressed!')
	warn_CB = lambda: showwarning('Warning', 'Warning Button Pressed!')
	info_CB = lambda: showinfo('Info', 'Info Button Pressed!')

	top = Tk()
	top.geometry('250x300')
	top.title('Road Signs')

	# формируются шаблон класса Button и кор­невое окно top. Эrо 
	# означает, что при каждом вызове в проrрамме объекта MyButton
	# этот объект вызывает Button (метод Tkinter.Button() создает 
	# кнопку) с указанием top в качестве первоrо параметра.
	My_button = pto(Button, top)
	
	# применяется первый созданный объект, MyButton, и на ero 
	# основе создаются шаблоны
	Crit_button = pto(My_button, command=crit_CB, bg='white', fg='red')
	Warn_button = pto(My_button, command=warn_CB, bg='yellow')
	Regu_button = pto(My_button, command=info_CB, bg='white')

	for each_sign in SIGNS:
		sign_type = SIGNS[each_sign]
		# Формируется строка, которую может вы­числить интерпретатор 
		# Python, включающая имя создаваемой кнопки, в качестве 
		# текстового параметра передается метка на кнопке, затем к 
		# пара­метрам применяется метод pack(). Если формируемый знак 
		# является за­прещающим, то буквы метки на кнопке преобразуются 
		# в прописные, в про­тивном случае в прописную преобразуются 
    "railroad crossing": WARN,
    "55\nspeed limit": REGU,
    "wrong way": CRIT,
    "merging traffic": WARN,
    "one way": REGU,
}

critCB = lambda: showerror("Error", "Error Button Pressed!")
warnCB = lambda: showwarning("Warning", "Warning Button Pressed!")
infoCB = lambda: showinfo("Info", "Info Button Pressed!")

top = Tk()
top.title("Road Signs")
Button(top, text="QUIT", command=top.quit, bg="red", fg="white").pack()

MyButton = pto(Button, top)
CritButton = pto(MyButton, command=critCB, bg="white", fg="red")
WarnButton = pto(MyButton, command=warnCB, bg="goldenrod1")
ReguButton = pto(MyButton, command=infoCB, bg="white")

for eachSign in SIGNS:
    signType = SIGNS[eachSign]
    cmd = "%sButton(text=%r%s).pack(fill=X, expand=True)" % (
        signType.title(),
        eachSign,
        ".upper()" if signType == CRIT else ".title()",
    )
    eval(cmd)

top.mainloop()
コード例 #16
0
ファイル: GUI_2.py プロジェクト: jayjihunlegacy/PythonTry
REGU = "regu"

SIGNS = {
    "do not enter": CRIT,
    "railroad crossing": WARN,
    "55\nspeed limit": REGU,
    "wrong way": CRIT,
    "meging traffic": WARN,
    "one way": REGU,
}

critCB = lambda: showerror("Error", "Error Button Pressed!")
warnCB = lambda: showwarning("Warning", "Warning Button Pressed!")
infoCB = lambda: showinfo("Info", "Info Button Pressed!")

top = tk.Tk()
top.title("Road Signs")
tk.Button(top, text="QUIT", command=top.quit, bg="red", fg="white").pack()

MyButton = pto(tk.Button, top)
CritButton = pto(MyButton, command=critCB, bg="white", fg='red')
WarnButton = pto(MyButton, command=warnCB, bg="goldnrod1")
ReguButton = pto(MyButton, command=infoCB, bg="white")

for eachSign in SIGNS:
    signType = SIGNS[eachSign]
    cmd = '%sButton (text={%r}{%s}).pack(fill=\"x\",expand=True)'.format(
        signType.title(), eachSign,
        ".upper()" if signType == CRIT else ".title()")
    eval(cmd)
top.mainloop()
コード例 #17
0
critCB = lambda: showerror('Error', 'Error Button Pressed!')
warnCB = lambda: showwarning('Warning', 'Warning Button Pressed!')
infoCB = lambda: showinfo('Info', 'Info Button Pressed!')

top = Tk()
top.title('Road Signs')

# bg在Mac上无效, 建议使用ttk替代Tkinter
Button(top,
       text='QUIT',
       command=top.quit,
       activebackground='red',
       activeforeground='white').pack()

MyButton = pto(Button, top)
CritButton = pto(MyButton,
                 command=critCB,
                 activebackground='white',
                 activeforeground='red')
WarnButton = pto(MyButton, command=warnCB, activebackground='goldenrod1')
ReguButton = pto(MyButton, command=infoCB, activebackground='white')

for eachSign in SIGNS:
    signType = SIGNS[eachSign]
    cmd = '%sButton(text=%r%s).pack(fill=X, expand=True)' %\
          (signType.title(), eachSign,
           '.upper()' if signType == CRIT else '.title()')
    eval(cmd)

top.mainloop()
コード例 #18
0
ファイル: pfaGUI2.py プロジェクト: zhangyue0503/python
SINS = {
    'do not enter': CRIT,
    'railroad crossing': WARN,
    '55\nspeed limit': REGU,
    'wrong way': CRIT,
    'merging traffic': WARN,
    'one way': REGU,
}

critCB = lambda: showerror('Error', 'Error Button Pressed!')
warnCB = lambda: showwarning('Warning', 'Warning Button Pressed!')
infoCB = lambda: showinfo('Info', 'Info Button Pressed!')

top = Tk()
top.title('Road Signs')
Button(top, text='QUIT', command=top.quit, bg='red', fg='white').pack()

MyButton = pto(Button, top)
CritButton = pto(MyButton, command=critCB, bg='white', fg='red')
WarnButton = pto(MyButton, command=warnCB, bg='goldenrod1')
ReguButton = pto(MyButton, command=infoCB, bg='white')

for eachSign in SINS:
    signType = SINS[eachSign]
    cmd = '%sButton(text=%r%s).pack(fill=X,expand=True)' % (signType.title(
    ), eachSign, '.upper()' if signType == CRIT else '.title()')
    # print cmd
    eval(cmd)

top.mainloop()
コード例 #19
0
ファイル: GUI_2.py プロジェクト: jayjihun/PythonTry
WARN = "warn"
CRIT = "crit"
REGU = "regu"

SIGNS = {
    "do not enter":CRIT,
    "railroad crossing":WARN,
    "55\nspeed limit":REGU,
    "wrong way":CRIT,
    "meging traffic":WARN,
    "one way":REGU,
    }

critCB = lambda : showerror("Error","Error Button Pressed!")
warnCB = lambda : showwarning("Warning","Warning Button Pressed!")
infoCB = lambda : showinfo("Info", "Info Button Pressed!")

top = tk.Tk()
top.title("Road Signs")
tk.Button(top,text="QUIT",command=top.quit,bg="red",fg="white").pack()

MyButton = pto(tk.Button,top)
CritButton = pto(MyButton,command=critCB,bg="white",fg='red')
WarnButton = pto(MyButton,command=warnCB,bg="goldnrod1")
ReguButton = pto(MyButton,command=infoCB,bg="white")

for eachSign in SIGNS:
    signType = SIGNS[eachSign]
    cmd = '%sButton (text={%r}{%s}).pack(fill=\"x\",expand=True)'.format(signType.title(),eachSign,".upper()" if signType == CRIT else ".title()")
    eval(cmd)
top.mainloop()