|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
为什么我的图片放在这个LogOn类里面就显示不出来,我是新手,希望大佬对Canvas和GUI类使用做指导,谢谢
from tkinter import *
from widgets import frame,label,button,entry
import webbrowser
oururl = 'http://www.baidu.com' #注册新账号url
weburl = 'http://www.baidu.com' #官网URL
gifdir = 'images/' #图片路径
class LogOn():
def __init__(self,parent=None):
win = Tk()
win.title('登录界面')
win.resizable(width=FALSE, height=FALSE)
can = Canvas(win)
can.pack(fill=BOTH)
can.config(width=400, height=200)
can.create_image(2, 2, image=self.getPhoto(), anchor=NW)
form = Frame(win)
form.pack(side=TOP, fill=X, padx=20, pady=5)
lbl = Label(form, width=5, text='账号')
ent = Entry(form)
lbl.pack(side=LEFT)
ent.pack(side=RIGHT, expand=YES, fill=X)
form2 = Frame(win)
form2.pack(side=TOP, fill=X, padx=20, pady=5)
lblpassword = Label(form2, width=5, text='密码')
entpassword = Entry(form2)
lblpassword.pack(side=LEFT)
entpassword.pack(side=RIGHT, expand=YES, fill=X)
form3 = Frame(win)
form3.pack(side=TOP, fill=X, padx=20, pady=5)
Button(form3, text='登录', bg='lightblue',command=self.logon).pack(fill=X, pady=10)
Button(form3, text='退出', bg='red',command=win.quit).pack(fill=X)
form4 = Frame(win)
form4.pack(side=TOP, fill=X, padx=20, pady=10)
lblnew = Label(form4, text='注册新的账号', font=('times', 10, 'bold'), fg='blue')
lblnew.pack(side=TOP, pady=5)
lblnew.bind('<Button-1>', self.openourweb)
lblweb = Label(form4, text='官网', font=('times', 20, 'bold'), fg='pink')
lblweb.pack(side=TOP)
lblweb.bind('<Button-1>', self.openweb)
def getPhoto(self):
logo = PhotoImage(file=gifdir + '李健5.gif')
return logo
def openourweb(self,event):
webbrowser.open(oururl, new=0, autoraise=True)
def openweb(self,event):
webbrowser.open(weburl, new=0, autoraise=True)
def logon(self):
pass
if __name__ == '__main__':
LogOn()
mainloop()
|
|