怎么设置Python的背景图片呢? (有代码)

nuptsww 2014-09-13 06:30:06
# -*- 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:", 6, show='')
password = make_entry(parent, "Password:", 6, 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()


####################################################################################################################################################


####################################################################################################################################################

def main():
root = Tk()
root.geometry("350x300+300+300")
app = MainWindow(root)
root.mainloop()

if __name__ == '__main__':
main()


在welcome那边设置了背景图片,但是运行后 图片是独立显示的,怎么设置为背景图片呢?
...全文
2055 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
panghuhu250 2014-09-18
  • 打赏
  • 举报
回复
自己用place把文字重叠在图片上.
ImN1 2014-09-18
  • 打赏
  • 举报
回复
QT不知道,tk要设layer

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧