나는 glade를 사용하여 guk로 gtk로 프로그램을 만들고 있습니다. 이 프로그램에는 몇 가지 메시지 대화 상자가 있습니다. 모든 사례에 대해 많은 메시지 대화 상자를 만들면 간단합니다. 그러나 하나의 메시지 대화 상자를 만들어 다른 텍스트로 다른 경우에 사용할 수 있습니까? 실제로는 간단합니다. 난 그냥 기본 텍스트를 변경하고 그것을 보여줄 필요가있다. 그러나 기본 텍스트 here 및 here을 변경하는 방법을 찾지 못했습니다.파이썬에서 gtk messagedialog의 기본 텍스트를 변경하는 방법?
아래는 샘플 코드입니다 : 나는 이런 식으로 뭔가로 변경할
from gi.repository import Gtk
def clicked1(widget):
response = dialog1.run()
if response == Gtk.ResponseType.OK:
print 'ok'
else:
print 'cancel'
dialog1.destroy()
def clicked2(widget):
response = dialog2.run()
if response == Gtk.ResponseType.OK:
print 'ok'
else:
print 'cancel'
dialog2.destroy()
def clicked3(widget):
response = dialog3.run()
if response == Gtk.ResponseType.OK:
print 'ok'
else:
print 'cancel'
dialog3.destroy()
builder = Gtk.Builder()
builder.add_from_file('gui.glade')
dialog1 = builder.get_object('dialog1')
dialog2 = builder.get_object('dialog2')
dialog3 = builder.get_object('dialog3')
builder.get_object('button1').connect('clicked', clicked1)
builder.get_object('button2').connect('clicked', clicked2)
builder.get_object('button3').connect('clicked', clicked3)
builder.get_object('window1').show_all()
Gtk.main()
from gi.repository import Gtk
def clicked1(widget):
**dialog.set_text(1)**
response = dialog.run()
if response == Gtk.ResponseType.OK:
print 'ok'
else:
print 'cancel'
dialog.destroy()
def clicked2(widget):
**dialog.set_text(2)**
response = dialog.run()
if response == Gtk.ResponseType.OK:
print 'ok'
else:
print 'cancel'
dialog.destroy()
def clicked3(widget):
**dialog.set_text(3)**
response = dialog.run()
if response == Gtk.ResponseType.OK:
print 'ok'
else:
print 'cancel'
dialog.destroy()
builder = Gtk.Builder()
builder.add_from_file('gui.glade')
**dialog = builder.get_object('dialog')**
builder.get_object('button1').connect('clicked', clicked1)
builder.get_object('button2').connect('clicked', clicked2)
builder.get_object('button3').connect('clicked', clicked3)
builder.get_object('window1').show_all()
Gtk.main()
나는 이것을 도와 주셔서 감사합니다. – user2435611
두 개의 라벨이 들어있는 상자를 반환하는'gtk_message_dialog_get_message_area()'를 사용하여 간단한 방법을 발견했습니다. :) – LiuLang
및 기본 텍스트 레이블에 액세스하는 방법? – user2435611