python tkinter과 파이썬코드 함께 실행하는 방법없나요?? 알려주세요

조회수 480회

대소문자를 바꿔주는 프로그램을 만들고 있는데 이문제로 이틀째 헤매고 있습니다. 밑에는 코드입니다. 밑에 코드를 실행하보면 root.mainloop()때문인지 gui만 실행이되네요... tkinter코드와 python코드가 같이 실행되게 할수있는 방법없을까요? 아직 초보라 질문올려봅니다.

*************************************************************************************************
from pynput.keyboard import Listener, Key, KeyCode
import pyperclip, clipboard
from tkinter import *

root = Tk()
root.title("Caps_Look")
root.geometry("200x220")
root.resizable(0, 0)
wall = PhotoImage(file = "On2.png")
wall_label = Label(image = wall)
wall_label.place(x = 23, y = 35)
button1 = Button(root, text="END",font="weight", command = exit)
button1.configure(foreground='red')

lbl = Label(root, text="Caps Look ON", font=("궁서체", 20))

lbl.pack()
button1.pack(side="bottom")
root.mainloop()


store = set()

HOT_KEYS = {
    'Caps_lock': set([ Key.caps_lock] )
}

def Caps_lock():
    copied = pyperclip.paste()
    text = copied.lower()
    clipboard.copy(text)

def handleKeyPress( key ):
    store.add( key )

    for action, trigger in HOT_KEYS.items():
        CHECK = all([ True if triggerKey in store else False for triggerKey in trigger ])

        if CHECK:
            try:
                func = eval( action )
                if callable( func ):
                    func()
            except NameError as err:
                print( err )

def handleKeyRelease( key ):
    if key in store:
        store.remove( key )

    # 종료
    if key == Key.esc:
        return False

with Listener(on_press=handleKeyPress, on_release=handleKeyRelease) as listener:
    listener.join()

  • (•́ ✖ •̀)
    알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)