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

nuptsww nuptsww 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
# -*- 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那边设置了背景图片,但是运行后 图片是独立显示的,怎么设置为背景图片呢?
...全文

相关推荐

PyQt5 实现给窗口设置背景图片的方法

PyQt5作为Python中一个强大的GUI库,提供了丰富的功能来帮助开发者创建出既实用又美观的应用程序。本文将详细介绍如何使用PyQt5中的`QPalette`类为窗口设置背景图片。

weixin_38700790

提升写Python体验 手把手教你设置酷炫的代码主题和背景图片

首先介绍了 Pycharm 的优势,为提升写 Python 的体验,我们可以选择导入自己喜欢的代码主题,设置自己喜欢的高清图片作为背景,还可以设置自动生成文件头注释,这样每次新建 .py 文件就会自动生成头注释。

叶庭云

pyqt5实现按钮添加背景图片以及背景图片的切换方法

### PyQt5实现按钮添加背景图片及背景图片切换方法详解#### 一、引言PyQt5 是一个广泛使用的Python库,用于开发图形用户界面(GUI)应用。

weixin_38579899

gtk背景图片设置

它支持多种编程语言,如C、Python、Vala等,为开发者提供了丰富的功能来构建美观且功能强大的应用程序。在GTK程序中设置背景图片是提升应用视觉效果的重要一环。首先,我们要理解GTK的窗口结构。

lianghe_work

css全屏背景图片设置,django加载图片路径详解

-- 这里的内容不会被背景图片遮挡 --> </div> </div></body></html>```在上面的代码中,`#bg` 是一个固定定位的div,它的宽度和高度都设为100%,使得它占据了整个浏览器窗口

weixin_38613681
评论 2
收藏 已收藏
分享
返回顶部
nuptsww
脚本语言 37,737 成员 34,208 内容