SORU
3 HAZİRAN 2010, PERŞEMBE


Nasıl Python ile basit bir ileti kutusu oluşturabilirim?

JavaScript alert() aynı etkiyi arıyorum.

Web tabanlı basit bir tercüman öğleden sonra Bükülmüş kullanarak yazdım.web. Temelde bir form ile Python kod bloğu göndermek ve istemci ve gelir kapar ve yürütür. İstiyorum yapabilir basit bir pop-up mesajı kalmadan yeniden yazmak ve daha bir sürü klişe wxPython veya Tkİnter kodu her zaman (beri kodu alır sundu üzerinden bir form ve sonra kaybolur).

TkMessageBox denedim:

import tkMessageBox
tkMessageBox.showinfo(title="Greetings", message="Hello World!")

ama bu tk simgesi ile arka planda başka bir pencere açılır. Bunu istemiyorum. Bazı basit wxPython kodu arıyordum ama her zaman bir sınıf kurma ve uygulama döngü vs. girmek gerekli. Basit, ücretsiz yakalamak Python kutusunda bir mesaj verme yolu?

CEVAP
7 Mart 2013, PERŞEMBE


Bu gibi ithalat ve tek satır bir kod kullanabilirsiniz:

import ctypes  # An included library with Python install.
ctypes.windll.user32.MessageBoxA(0, "Your text", "Your title", 1)

Veya bir fonksiyon (Mbox) gibi tanımlayın:

import ctypes  # An included library with Python install.
def Mbox(title, text, style):
    ctypes.windll.user32.MessageBoxA(0, text, title, style)
Mbox('Your title', 'Your text', 1)

Stilleri aşağıdaki gibidir: not

##  Styles:
##  0 : OK
##  1 : OK | Cancel
##  2 : Abort | Retry | Ignore
##  3 : Yes | No | Cancel
##  4 : Yes | No
##  5 : Retry | No 
##  6 : Cancel | Try Again | Continue

İyi eğlenceler!

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Randall P Studios

    Randall P St

    27 AĞUSTOS 2009
  • TheJoeycool2010

    TheJoeycool2

    12 Temmuz 2010
  • tutvid

    tutvid

    19 AĞUSTOS 2006