在以下代码中添加背景import time from tkinter import * import turtle # 导入turtle模块 import time class ShowWelcome(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.root = master # 定义内部变量root self.createPage() def createPage(self): canva = Canvas(self.root, width=500, height=500) # 设定画布 canva.pack() theScreen = turtle.TurtleScreen(canva) # 设定turtle屏幕 path = turtle.RawTurtle(theScreen) # 设定画笔 path.color('#87CEFA') # 设定画笔颜色 path.left(180) path.up() # 抬笔 path.forward(80) path.down() # 落笔 path.write('欢迎进入本系统', font=('宋体', 18)) path.up() path.forward(100) path.down() path.left(90) path.forward(100) path.left(90) path.forward(350) time.sleep(3) canva.pack_forget()
时间: 2024-04-08 16:33:25 浏览: 55
在以下代码中添加背景:
```python
import time
from tkinter import *
import turtle # 导入turtle模块
import time
class ShowWelcome(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.root = master # 定义内部变量root
self.createPage()
def createPage(self):
canva = Canvas(self.root, width=500, height=500) # 设定画布
canva.pack()
theScreen = turtle.TurtleScreen(canva) # 设定turtle屏幕
path = turtle.RawTurtle(theScreen) # 设定画笔
# 添加背景
bg_image = PhotoImage(file="background.png")
canva.create_image(0, 0, anchor=NW, image=bg_image)
path.color('#87CEFA') # 设定画笔颜色
path.left(180)
path.up() # 抬笔
path.forward(80)
path.down() # 落笔
path.write('欢迎进入本系统', font=('宋体', 18))
path.up()
path.forward(100)
path.down()
path.left(90)
path.forward(100)
path.left(90)
path.forward(350)
time.sleep(3)
canva.pack_forget()
```
请注意,上述代码中的`background.png`是你想要设置的背景图片文件名,你需要将其替换为你实际使用的背景图片文件名。
阅读全文