Answers for "python focus window"

1

python change window focus

import win32gui

def windowEnumerationHandler(hwnd, top_windows):
    top_windows.append((hwnd, win32gui.GetWindowText(hwnd)))

if __name__ == "__main__":
    results = []
    top_windows = []
    win32gui.EnumWindows(windowEnumerationHandler, top_windows)
    for i in top_windows:
        if "notepad" in i[1].lower():
            print i
            win32gui.ShowWindow(i[0],5)
            win32gui.SetForegroundWindow(i[0])
            break
Posted by: Guest on June-20-2021
-1

python tkinter focus on entry

from Tkinter import *
root = Tk()
frame=Frame(root,width=100,heigh=100,bd=11)
frame.pack()
label = Label(frame,text="Enter a digit that you guessed:").pack()
entry= Entry(frame,bd=4)
entry.pack()
entry.focus()
button1=Button(root,width=4,height=1,text='ok')
button1.pack()

root.mainloop()
Posted by: Guest on August-13-2020

Python Answers by Framework

Browse Popular Code Answers by Language