window = tk.Tk() window.title("三维显示系统登录界面") window.geometry("805x660") # 背景画布 import tkinter canvas = tk.Canvas(window,width=10250,height=100) img_gif = tkinter.PhotoImage(file='title3.gif') tkinter.Label(window, image=img_gif).place(relx=-0, rely=0) canvas.pack()sign_in_button = tk.Button(window,text="登录",command=sign_in_f) sign_up_button = tk.Button(window,text="注册",command=sign_up_f) sign_in_button.place(x=350,y=600) sign_up_button.place(x=470,y=600)加入文件调用按钮
时间: 2024-02-22 12:57:54 浏览: 166
下面是修改后的代码,加入了一个按钮,可以让用户选择文件:
```python
import tkinter as tk
from tkinter import filedialog
def sign_in_f():
pass
def sign_up_f():
pass
def open_file():
filename = filedialog.askopenfilename(initialdir="/", title="Select file",
filetypes=(("Text files", "*.txt*"), ("all files", "*.*")))
print(filename)
window = tk.Tk()
window.title("三维显示系统登录界面")
window.geometry("805x660")
# 背景画布
canvas = tk.Canvas(window, width=10250, height=100)
img_gif = tk.PhotoImage(file='title3.gif')
tk.Label(window, image=img_gif).place(relx=-0, rely=0)
canvas.pack()
# 登录和注册按钮
sign_in_button = tk.Button(window, text="登录", command=sign_in_f)
sign_up_button = tk.Button(window, text="注册", command=sign_up_f)
sign_in_button.place(x=350, y=600)
sign_up_button.place(x=470, y=600)
# 文件调用按钮
file_button = tk.Button(window, text="选择文件", command=open_file)
file_button.place(x=600, y=600)
window.mainloop()
```
在这个例子中,我们定义了一个新的函数`open_file()`,当用户点击文件按钮时,调用该函数打开文件对话框。当用户选择文件后,文件的路径会打印到控制台上。你可以根据需要修改`open_file()`函数的实现,以便在GUI中显示所选文件的路径。
阅读全文