2017-02-01 66 views
0

我正在用一些定時器創建一個小小的跟蹤器窗口,我希望能夠使其點擊。我還沒有找到解決這個問題的辦法。窗口本身被創建,定時器正在工作。我唯一無法弄清的是,如果有可能使窗口點擊。我正在使用tkinter包。Python3 tkinter是否有可能使框架能夠被點擊通過?

我的代碼可以在這裏找到:http://pastebin.com/qSFZqpQ6 - 由於我是Python的新手,所以我可能肯定會在我的設置上工作,這有點麻煩。從鏈接

import win32api 
import time 
from tkinter import * 

input = "0.00" 
counter = time.clock() 

flaskmult = 1.11 

positionX = 2300 
positionY = 1100 

witchfireTime = 6 
dyingrumiTime = 4.8 
basaltTime = 7.9 

activeTime = False 
started = False 

def keyWasUnPressed(): 
    global counter 
    counter = time.clock() 
    global started 
    started = True 


def isKeyPressed(key): 
    #"if the high-order bit is 1, the key is down; otherwise, it is up." 
    return (win32api.GetKeyState(key) & (1 << 7)) != 0 

root = Tk() 

root.title("Flasktracker") 
root.overrideredirect(1) 
root.geometry("+"+str(positionX)+"+"+str(positionY)) 
root.wm_attributes("-topmost", 1) 

labelText = StringVar() 
label = Label(root,textvariable=labelText, relief=FLAT, font = "Helvetica 36 bold italic").grid(row=0, column=0) 
labelText.set("Witchfire: ") 

labelText2 = StringVar() 
label2 = Label(root,textvariable=labelText2, relief=FLAT, font = "Helvetica 36 bold italic").grid(row=0, column=1) 
labelText2.set(input) 

labelText3 = StringVar() 
label3 = Label(root,textvariable=labelText3, relief=FLAT, font = "Helvetica 36 bold italic").grid(row=1, column=0) 
labelText3.set("Dying/Rumi: ") 

labelText4 = StringVar() 
label4 = Label(root,textvariable=labelText4, relief=FLAT, font = "Helvetica 36 bold italic").grid(row=1, column=1) 
labelText4.set(input) 

labelText5 = StringVar() 
label5 = Label(root,textvariable=labelText5, relief=FLAT, font = "Helvetica 36 bold italic").grid(row=2, column=0) 
labelText5.set("Basalt: ") 

labelText6 = StringVar() 
label6 = Label(root,textvariable=labelText6, relief=FLAT, font = "Helvetica 36 bold italic").grid(row=2, column=1) 
labelText6.set(input) 

key = ord('1') 

wasKeyPressedTheLastTimeWeChecked = False 

def calcTime(timer): 
    return (timer*flaskmult)-(time.clock()-counter) 

while True: 
    keyIsPressed = isKeyPressed(key) 
    if not keyIsPressed and wasKeyPressedTheLastTimeWeChecked: 
     keyWasUnPressed() 
    wasKeyPressedTheLastTimeWeChecked = keyIsPressed 
    activeTime = False 
    if started and calcTime(witchfireTime)>0: 
     labelText2.set('{:0.2f}'.format(calcTime(witchfireTime))) 
     activeTime = True 
    else: 
     labelText2.set("0.00") 
    if started and calcTime(dyingrumiTime)>0: 
     labelText4.set('{:0.2f}'.format(calcTime(dyingrumiTime))) 
     activeTime = True 
    else: 
     labelText4.set("0.00") 
    if started and calcTime(basaltTime)>0: 
     labelText6.set('{:0.2f}'.format(calcTime(basaltTime))) 
     activeTime = True 
    else: 
     labelText6.set("0.00") 
    if activeTime: 
     root.attributes('-alpha',1) 
    else: 
     root.attributes('-alpha',0) 
    time.sleep(0.001) 
    root.update_idletasks() 
    root.update() 
+1

確切地點擊了什麼意思?它僅僅是一個Windows概念嗎? –

+0

你不需要同時調用'update'和'update_idletasks'。後者只是做前者的一個子集。 –

回答

0

代碼不,這是不可能與Tkinter的做到這一點。有可能通過一定數量的特定於平臺的擴展來實現這一點,但是如果你走這條路線,那麼你可能只需編寫一個本地解決方案,而不需要tkinter。

相關問題