DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Curious about the future of data-driven systems? Join our Data Engineering roundtable and learn how to build scalable data platforms.

Data Engineering: The industry has come a long way from organizing unstructured data to adopting today's modern data pipelines. See how.

Threat Detection: Learn core practices for managing security risks and vulnerabilities in your organization — don't regret those threats!

Managing API integrations: Assess your use case and needs — plus learn patterns for the design, build, and maintenance of your integrations.

Related

  • Build a Multilingual Chatbot With FastAPI and Google Cloud Translation
  • Integrated Gradients: AI Explainability for Regulated Industries
  • How to Simplify Complex Conditions With Python's Match Statement
  • Unleashing the Power of Gemini With LlamaIndex

Trending

  • Microservices Design Patterns: Essential Architecture and Design Guide
  • How to Submit a Post to DZone
  • DZone's Article Submission Guidelines
  • High-Performance Reactive REST API and Reactive DB Connection Using Java Spring Boot WebFlux R2DBC Example
  1. DZone
  2. Coding
  3. Languages
  4. Use Python Win32gui Draw Something And Get Info On Some Window Specialized By Points

Use Python Win32gui Draw Something And Get Info On Some Window Specialized By Points

By 
Snippets Manager user avatar
Snippets Manager
·
Oct. 15, 09 · Code Snippet
Likes (0)
Comment
Save
Tweet
Share
5.2K Views

Join the DZone community and get the full member experience.

Join For Free

import win32gui
from re import match
def draw_line():
    print 'x1,y1,x2,y2?'
    s=raw_input()
    if match('\d+,\d+,\d+,\d+',s):
        x1,y1,x2,y2=s.split(',')
        x1=int(x1)
        y1=int(y1)
        x2=int(x2)
        y2=int(y2)
        hwnd=win32gui.WindowFromPoint((x1,y1))
        hdc=win32gui.GetDC(hwnd)
        x1c,y1c=win32gui.ScreenToClient(hwnd,(x1,y1))
        x2c,y2c=win32gui.ScreenToClient(hwnd,(x2,y2))
        win32gui.MoveToEx(hdc,x1c,y1c)
        win32gui.LineTo(hdc,x2c,y2c)
        win32gui.ReleaseDC(hwnd,hdc)
    main()
def draw_point():
    print 'x,y,color?'
    s=raw_input()
    if match('\d+,\d+,\d+',s):
        x,y,color=s.split(',')
        x=int(x)
        y=int(y)
        color=int(color)
        hwnd=win32gui.WindowFromPoint((x,y))
        hdc=win32gui.GetDC(hwnd)
        x1,y1=win32gui.ScreenToClient(hwnd,(x,y))
        win32gui.SetPixel(hdc,x1,y1,color)
        win32gui.ReleaseDC(hwnd,hdc)
    main()
def get_pixel_col():
    print 'x,y?'
    s=raw_input()
    if match('\d+,\d+',s):
        x,y=s.split(',')
        x=int(x)
        y=int(y)
        hwnd=win32gui.WindowFromPoint((x,y))
        hdc=win32gui.GetDC(hwnd)
        x1,y1=win32gui.ScreenToClient(hwnd,(x,y))
        color=win32gui.GetPixel(hdc,x1,y1)
        win32gui.ReleaseDC(hwnd,hdc)
        print color
    main()
def get_current_pos_info():
    x,y=win32gui.GetCursorPos()
    hwnd=win32gui.WindowFromPoint((x,y))
    hdc=win32gui.GetDC(hwnd)
    x1,y1=win32gui.ScreenToClient(hwnd,(x,y))
    print x,y,win32gui.GetPixel(hdc,x1,y1)
    win32gui.ReleaseDC(hwnd,hdc)
    main()
def main():
    print ('''l. draw line
p. draw point
g. get pixel color
c. get current mouse position's info''')
    s=raw_input()
    if s.lower()=='l':
        draw_line()
    if s.lower()=='p':
        draw_point()
    if s.lower()=='g':
        get_pixel_col()
    if s.lower()=='c':
        get_current_pos_info()
main()
Python (language)

Opinions expressed by DZone contributors are their own.

Related

  • Build a Multilingual Chatbot With FastAPI and Google Cloud Translation
  • Integrated Gradients: AI Explainability for Regulated Industries
  • How to Simplify Complex Conditions With Python's Match Statement
  • Unleashing the Power of Gemini With LlamaIndex

Partner Resources


Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: