【发布时间】:2018-04-29 01:21:15
【问题描述】:
在我将小部件状态更改为禁用后。小部件的视图正在更改为禁用视图。我不想改变小部件的视图,只改变小部件的状态。我怎样才能确保这一点?
谢谢。
btn = Gtk.Button("example")
btn.set_sensitive(False) # this code makes button disabled.
btn.set_view("normal") # I know set_view method does not exist but is there a method like this to change disabled view to normal view.
我的完整代码
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
class TitledEntry(Gtk.VBox):
def __init__(self, title=None, text=""):
Gtk.VBox.__init__(self, spacing=2)
title = Gtk.Label(label=title, halign=Gtk.Align.START)
self.add(title)
entry = Gtk.Entry(text=text)
self.add(entry)
self.title_label = title
self.entry = entry
self.show_all()
class AgeBox(Gtk.HBox):
def __init__(self, age=0):
Gtk.HBox.__init__(self, halign=Gtk.Align.START)
lb = Gtk.Label("Age : ")
self.add(lb)
agebutton = Gtk.SpinButton(adjustment=Gtk.Adjustment(age, 0, 1000, 1, 10, 0),
numeric=True, update_policy=Gtk.SpinButtonUpdatePolicy.IF_VALID)
agebutton.set_value(age)
self.add(agebutton)
self.agebutton = agebutton
class HumanTemp(Gtk.VBox):
def __init__(self, nick="", age=0, country="", language=""):
Gtk.VBox.__init__(self, spacing=3, border_width=5, halign=Gtk.Align.CENTER)
temp_name = Gtk.Label()
temp_name.set_markup("<span font_weight='bold'>Human</span>")
self.pack_start(temp_name, False, False, 0)
nick_box = TitledEntry("Nick", nick)
self.pack_start(nick_box, False, False, 0)
age_box = AgeBox(age)
self.pack_start(age_box, False, False, 0)
country_box = TitledEntry("Country", country)
self.pack_start(country_box, False, False, 0)
language_box = TitledEntry("Language", language)
self.pack_start(language_box, False, False, 0)
self.show_all()
class AnimTemp(Gtk.VBox):
def __init__(self, nick="", age=0, kind="wolf"):
Gtk.VBox.__init__(self, spacing=3, border_width=5, halign=Gtk.Align.CENTER)
temp_name = Gtk.Label()
temp_name.set_markup("<span font_weight='bold'>Animal</span>")
self.pack_start(temp_name, False, False, 0)
nick_box = TitledEntry("Nick", nick)
self.pack_start(nick_box, False, False, 0)
age_box = AgeBox(age)
self.pack_start(age_box, False, False, 0)
kind_box = Gtk.VBox()
self.pack_start(kind_box, False, False, 0)
kind_name = Gtk.Label("Kind", halign=Gtk.Align.START)
kind_box.pack_start(kind_name, False, False, 0)
box = Gtk.HBox()
kind_box.pack_start(box, False, False, 0)
wolf = Gtk.RadioButton("Wolf",group=None)
box.pack_start(wolf, False, False, 0)
tiger = Gtk.RadioButton("Tiger", group=wolf)
box.pack_start(tiger, False, False, 0)
if kind == "wolf":
wolf.set_active(True)
else:
tiger.set_active(True)
self.show_all()
class ElfTemp(Gtk.VBox):
def __init__(self, nick="", age=0, clan="terran", race="night"):
Gtk.VBox.__init__(self, spacing=3, border_width=5, halign=Gtk.Align.CENTER)
temp_name = Gtk.Label()
temp_name.set_markup("<span font_weight='bold'>Elf</span>")
self.pack_start(temp_name, False, False, 0)
nick_box = TitledEntry("Nick", nick)
self.pack_start(nick_box, False, False, 0)
age_box = AgeBox(age)
self.pack_start(age_box, False, False, 0)
clan_box = Gtk.VBox(halign=Gtk.Align.START)
self.pack_start(clan_box, False, False, 0)
clan_name = Gtk.Label("Clan", halign=Gtk.Align.START)
clan_box.pack_start(clan_name, False, False, 0)
box = Gtk.HBox()
clan_box.pack_start(box, False, False, 0)
terran = Gtk.RadioButton("Terran",group=None)
box.pack_start(terran, False, False, 0)
vanu = Gtk.RadioButton("Vanu", group=terran)
box.pack_start(vanu, False, False, 0)
atlas = Gtk.RadioButton("Atlas", group=terran, halign=Gtk.Align.CENTER)
clan_box.pack_start(atlas, False, False, 0)
race_box = Gtk.VBox()
self.pack_start(race_box, False, False, 0)
race_name = Gtk.Label("Race", halign=Gtk.Align.START)
race_box.pack_start(race_name, False, False, 0)
box = Gtk.HBox()
race_box.pack_start(box, False, False, 0)
night = Gtk.RadioButton("Night", group=None)
box.pack_start(night, False, False, 0)
blood = Gtk.RadioButton("Blood", group=night)
box.pack_start(blood, False, False, 0)
if clan == "terran":
terran.set_active(True)
elif clan == "vanu":
vanu.set_active(True)
else:
atlas.set_active(True)
if race == "night":
night.set_active(True)
else:
blood.set_active(True)
self.show_all()
class SelectTemplateWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Select a Temlpate")
self.resize(581, 506)
scw = Gtk.ScrolledWindow(visible=True)
self.add(scw)
flbox = Gtk.FlowBox(min_children_per_line=2, valign=Gtk.Align.START)
scw.add(flbox)
keltas = ElfTemp("Keltas", 24, "terran", "blood")
flbox.add(keltas)
illidan = ElfTemp("Illidan", 47, "vanu", "night")
flbox.add(illidan)
jack = HumanTemp("Jack", 21, "Canada", "English")
flbox.add(jack)
santiago = HumanTemp("Santiago", 37, "Spain", "Spanish")
flbox.add(santiago)
moon_wolf = AnimTemp("Moon Wolf", 941, "wolf")
flbox.add(moon_wolf)
lexar = AnimTemp("Lexar", 438, "tiger")
flbox.add(lexar)
flbox.show_all()
win = SelectTemplateWindow()
win.connect("delete-event", Gtk.main_quit)
win.show()
Gtk.main()
我不想编辑 FlowBoxChild(模板),但是当我将敏感设置为 False 时,视图正在改变(视图不好)。如果不对False敏感,我怎么能做到这一点
【问题讨论】:
-
你能发布一个 MCVE 吗?
-
@theGtknerd,我编辑了
-
“正常”是什么意思?让它再次敏感?为此,您将使用
btn.set_sensitive(True)。 -
@SvenFestersen,禁用模式下的小部件看起来与正常模式不同,我只想更改禁用模式下的小部件视图而不更改禁用模式。
-
@Nomad:只是为了确保我做对了:您希望按钮看起来很敏感但对点击没有反应?这对您的用户来说非常具有误导性(并且可能令人沮丧),我建议不要这样做。但是,如果您想这样做,我认为您可以将样式从活动状态按钮转移到禁用按钮。我不知道如何详细地做到这一点。这个问题可能包含一些提示:stackoverflow.com/questions/38158289/…