다음 코드는 MS Windows에서 올바르게 작동합니다 (를 누르면 스크립트가 종료 됨 q
).
import Tkinter as tk
class App():
def __init__(self):
self.root = tk.Tk()
self.root.geometry("{0}x{1}+0+0".format(
self.root.winfo_screenwidth(), self.root.winfo_screenheight())
)
self.root.overrideredirect(True)
tk.Label(text="some text here").grid()
self.root.bind('q', self.appexit)
self.root.mainloop()
def appexit(self, event):
self.root.destroy()
App()
"윈도우 관리자가없는"데비안 환경에서 실행하려고했습니다 (콘솔로 부팅하고 run startx
, 스크립트를 실행 .xinitrc
하는 유일한 명령).
스크립트가 예상대로 시작되지만 키를 눌러도 q
아무 작업도 수행되지 않습니다 ( X
닫고 텍스트 콘솔로 돌아갈 것으로 예상 했습니다). 나는 나중에 self.root.focus()
이전의 경우를 대비하여 추가하려고했지만 mainloop()
도움이되지 않았습니다.
MS Windows와 Debian 환경간에 이러한 동작이 다른 이유는 무엇일까요?
overrideredirect 프로그램을 사용하면 창 관리와의 연결이 끊어져 눌러 진 키에 대한 정보를 얻을 수없고 초점을 맞출 수없는 것 같습니다.
MS Windows는 하나의 큰 창 관리자이므로 overrideredirect
해당 시스템에서 작동하지 않는 것 같습니다 .
self.root.attributes('-fullscreen', True)
대신 사용할 수 있습니다 .self.root.overrideredirect(True)
BTW : 테스트 용으로 사용 self.root.after(5000, self.root.destroy)
합니다. 제어 할 수 없을 때 5 초 후에 창을 죽이는 데 사용 합니다.
편집하다:
일부 (작동하는) fullscreen
.
로 overrideredirect
리눅스 프로그램에 대한 구속력이없는 작업을 수행하므로 키보드 이벤트를 얻을 수 있습니다, 당신은 초점을 맞출 수 없습니다 Entry()
. 그러나 마우스와 Button()
작동합니다. overrideredirect
버튼이 있거나없는 "스플래시 화면"에 적합합니다.
import Tkinter as tk
class App():
def __init__(self):
self.root = tk.Tk()
# this works
self.root.attributes('-fullscreen', True)
# this doesn't work
#self.root.overrideredirect(True)
#self.root.geometry("800x600+100+100") # to see console behind
#self.root.after(5000, self.appexit) # to kill program after 5s
self.root.bind('q', self.q_pressed)
tk.Label(text="some text here").grid()
e = tk.Entry(self.root)
e.grid()
e.focus() # focus doesn't work with overrideredirect
tk.Button(self.root, text='Quit', command=self.appexit).grid()
self.root.mainloop()
def q_pressed(self, event):
print "q_pressed"
self.root.destroy()
def appexit(self):
print "appexit"
self.root.destroy()
App()
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다