问题描述
嘿,我有一个关于操作系统的学校项目,但是遇到了问题。我无法在桌面上打开窗口。
我使用框架创建了窗口,但是无法最小化,最大化并在Canvas
上移动窗口。
我在下面共享我的代码:
from tkinter import *
import desktop_features.load_images as LoadImage
import os
lastx,lasty=None,None
default_window_size=(500,500)
default_window_coordinates=(150,150)
def move_window(e):
desk.coords(window,e.x,e.y)
def on_l1(e):
l1.config(fg='black',font=("Georgia",10,'underline'))
def off_l1(e):
l1.config(fg='black',10))
def exit_requested(e):
desk.delete(window)
button.destroy()
win.destroy()
window_size="minimum"
def on_close_button(e):
close_button.config(image=hover_close_window_button)
def off_close_button(e):
close_button.config(image=close_window_button)
def on_min_max_button(e):
min_max_button.config(image=hover_max_min_window_button)
def off_min_max_button(e):
min_max_button.config(image=max_min_window_button)
window_size="minimum"
def resize_requested(e=None):
global window_size,default_window_size
if window_size=="minimum":
win.config(height=s_height-53,width=s_width)
desk.coords(window,s_width/2,s_height/2)
win.pack(fill="both")
window_size="maximum"
elif window_size=="maximum":
win.config(height=default_window_size[0],width=default_window_size[1])
desk.coords(window,lastx,lasy)
window_size="minimum"
def on_hide_button(e):
hide_button.config(image=hover_hide_window_button)
def off_hide_button(e):
hide_button.config(image=hide_window_button)
window_hide=True
def hide_requested(e=None):
global window_hide
if window_hide==False:
desk.itemconfigure(window,state='normal')
window_hide=True
elif window_hide==True:
desk.itemconfigure(window,state='hidden')
window_hide=False
#################################################################
window_open=True
def main(desktop,window_color,directory,taskbar,font_color,screen_height,screen_width):
global window_open
if window_open:
window_open=False
global win,button,close_window_button,hover_close_window_button,close_button,window,desk,window_hide
global max_min_window_button,hover_max_min_window_button,min_max_button,hide_window_button,hover_hide_window_button,hide_button,icon,l1
global s_height,s_width,default_window_coordinates,default_window_size
s_height,s_width=screen_height,screen_width
desk=desktop
win=Frame(desktop,height=default_window_size[0],width=default_window_size[1],bg="black",highlightthickness=3,highlightbackground=window_color)
win.pack(expand=True)
window=desktop.create_window((default_window_coordinates[0],default_window_coordinates[1]),window=win,state='normal',anchor="nw")
title_bar=Frame(win,height=25,width=10,bg=window_color)
title_bar.pack(fill="x")
icon=LoadImage.Images(r""+str(directory)+r"img\red_mars_window\window_icon\user_icon.jpg")
win_icon=Label(title_bar,image=icon)
win_icon.pack(side="left",padx=2,pady=2)
win_title=Label(title_bar,text="Paint - Red Mars OS",fg=font_color,bg=window_color)
win_title.pack(side="left",padx=5)
win.bind("<B1-Motion>",move_window)
win_icon.bind("<B1-Motion>",move_window)
win_title.bind("<B1-Motion>",move_window)
button=Button(taskbar,text="Hello",command=hide_requested)
button.pack(side="left")
close_window_button=LoadImage.Images(r""+str(directory)+r"img\red_mars_window\normal_icon\close_icon.png")
hover_close_window_button=LoadImage.Images(r""+str(directory)+r"img\red_mars_window\hover_icon\close_icon.png")
close_button=Label(title_bar,image=close_window_button,border=0)
close_button.pack(side="right",pady=2)
close_button.bind("<Enter>",on_close_button)
close_button.bind("<Leave>",off_close_button)
close_button.bind("<Button-1>",exit_requested)
max_min_window_button=LoadImage.Images(r""+str(directory)+r"img\red_mars_window\normal_icon\max_min_icon.png")
hover_max_min_window_button=LoadImage.Images(r""+str(directory)+r"img\red_mars_window\hover_icon\min_max_icon.png")
min_max_button=Label(title_bar,image=max_min_window_button,border=0)
min_max_button.pack(side="right",pady=2)
min_max_button.bind("<Enter>",on_min_max_button)
min_max_button.bind("<Leave>",off_min_max_button)
min_max_button.bind("<Button-1>",resize_requested)
hide_window_button=LoadImage.Images(r""+str(directory)+r"img\red_mars_window\normal_icon\hide_icon.png")
hover_hide_window_button=LoadImage.Images(r""+str(directory)+r"img\red_mars_window\hover_icon\hide_icon.png")
hide_button=Label(title_bar,image=hide_window_button,border=0)
hide_button.pack(side="right",pady=2)
hide_button.bind("<Enter>",on_hide_button)
hide_button.bind("<Leave>",off_hide_button)
hide_button.bind("<Button-1>",hide_requested)
else:
hide_requested()
如果您需要完整的代码,请通过以下链接下载: https://drive.google.com/file/d/19-_htkv1VSr77RhwaDA4QafwwRVVBw4R/view?usp=drivesdk
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)