Python Tkinter 显示的问题 20

我想设置整个窗口的背景,怎么样才能使输入密码部分显示在图片中间#-*-coding:cp936-*-importTkinterfromTkinterimportTk,Te... 我想设置整个窗口的背景,
怎么样才能使输入密码部分 显示在图片中间
# -*- coding: cp936 -*-

import Tkinter
from Tkinter import Tk, Text, BOTH, W, N, E, S
from ttk import Frame, Button, Label, Style
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PIL import ImageTk
class MessageBoxDlg(QDialog):
def __init__(self,parent=None):
super(MessageBoxDlg,self).__init__(parent)
self.setWindowTitle("Message")
self.label=QLabel("FATAL ERROR !")
questionButton=QPushButton("Exit now")
gridLayout=QGridLayout(self)
gridLayout.addWidget(self.label,0,0,1,2)
gridLayout.addWidget(questionButton,1,0)
self.connect(questionButton,SIGNAL("clicked()"),self.slotQuestion)

def slotQuestion(self):
sys.exit()

try:
import tkinter as tk
except ImportError:
import Tkinter as tk

failure_max = 3
passwords = [('sww', 'sww')]

CHECK=11
def make_entry(parent, caption, width=None, **options):

tk.Label(parent, text=caption).pack(side=tk.TOP)
entry = tk.Entry(parent, **options)
if width:
entry.config(width=width)
entry.pack(side=tk.TOP, padx=10, fill=tk.BOTH)
return entry
def enter(event):
check_password()
def check_password(failures=[]):
# Collect 1's for every failure and quit program in case of failure_max failures
print(user.get(), password.get())
global CHECK
if (user.get(), password.get()) in passwords:
root.destroy()
print('Logged in')
CHECK=1
return
failures.append(1)
if sum(failures) >= failure_max:
root.destroy()
raise SystemExit('Unauthorized login attempt')
CHECK=0
app=QApplication(sys.argv)
MessageBox=MessageBoxDlg()
MessageBox.show()
app.exec_()
else:
root.title('Try again. Attempt %i/%i' % (sum(failures)+1, failure_max))
CHECK=0
root = tk.Tk()
root.geometry('300x160')
root.title('Enter your information')
img = ImageTk.PhotoImage(file='bg.jpg')
label=Tkinter.Label(root,text='\n\n ****** WELCOME ******\n\n GEM Decision Support System\n\n Please input your personal information:',fg='red',image=img)
label.config(font=('helvetica',14))
label.pack(side=tk.TOP)
#frame for window margin
parent = tk.Frame(root, padx=10, pady=10)
parent.pack(fill=tk.BOTH, expand=True)
#entrys with not shown text
user = make_entry(parent, "User name:", 16, show='')
password = make_entry(parent, "Password:", 16, show="*")
#button to attempt to login
b = tk.Button(parent, borderwidth=4, text="Login", width=8, pady=6, command=check_password)
b.pack(side=tk.BOTTOM)
password.bind('<Return>', enter)
user.focus_set()
parent.mainloop()
if(CHECK!=1):
sys.exit()

if __name__ == '__main__':
main()
展开
 我来答
  • 你的回答被采纳后将获得:
  • 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏20(财富值+成长值)
WM_THU
2014-09-16 · TA获得超过7164个赞
知道大有可为答主
回答量:4285
采纳率:80%
帮助的人:3929万
展开全部
把bg.jpg传上来,要不没法调试。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式