我是程式新手
现在在使用tkinter想写一个萤幕截图的工具
我是把两个tkinter视窗分别写进两个class
import tkinter
class window_main():
def __init__(self):
self.window = tkinter.Tk()
self.set_window_title("Screen Shot")
self.create_widgets()
self.window.mainloop()
def set_window_title(self, title):
self.window.title(title)
def create_widgets(self):
self.button_st = tkinter.Button(self.window)
self.button_st["text"] = "Screen Shot"
self.button_st["height"] = 2
self.button_st["width"] = 13
self.button_st["command"] = self.screen_shot
self.button_st.grid(row = 0, column = 0,
padx = 5, pady = 5)
self.button_exit = tkinter.Button(self.window)
self.button_exit["text"] = "Exit"
self.button_exit["height"] = 2
self.button_exit["width"] = 13
self.button_exit["command"] = self.event_exit
self.button_exit.grid(row = 1, column = 0,
padx = 5, pady = 5)
def wind_hide(self):
self.window.withdraw()
def wind_show(self):
self.window.deiconify()
def screen_shot(self):
self.wind_hide()
self.sub_app = window_full_screen()
def event_exit(self):
self.window.destroy()
class window_full_screen():
def __init__(self):
self.window_exist = True
self.window = tkinter.Tk()
self.window.attributes("-fullscreen", True)
self.window.attributes("-alpha", 0.25)
self.create_canvas()
self.window.bind("<Escape>", self.event_exit)
self.window.mainloop()
def create_canvas(self):
self.canvas = tkinter.Canvas(self.window,
width = self.window.winfo_screenwidth(),
height =
self.window.winfo_screenheight())
self.canvas.place(x = 0, y = 0)
self.canvas.create_line(0, 0, 1440, 900)
def event_exit(self, event):
self.window_exist = False
self.window.destroy()
app = window_main()
当window_main打开window_full_screen的时候
我想把window_main给隐藏 使用withdraw
但当我把window_full_screen关闭后
我目前想不到要如何把window_main叫回来
虽然我知道要使用deiconify
但要如何在window_full_screen触发关闭后 让window_main也能触发事件
程式码原始档
https://github.com/kurapica1106/screenshot_and_compare/
blob/screenshot/screenshot_2022_02_16_01_.py
缩网址
https://reurl.cc/xOKYyz