如何创建一个仅在某些全局 FrontEnd 设置的值是并且将自毁并在按下它后将其设置为的整行Button
时才显示的内容?False
Column
True
我需要这样的东西:
Column[{"Item 1", "Item 2",
Dynamic[If[
Last@Last@Options[$FrontEnd, "VersionedPreferences"] === False,
Button["Press me!",
SetOptions[$FrontEnd, "VersionedPreferences" -> True]],
Sequence @@ {}]]}]
但是使用此代码,Button
按下后不会消失。有没有可能让它自毁?
最终解决方案基于belisarius和mikuszefski的想法:
PreemptProtect[SetOptions[$FrontEnd, "VersionedPreferences" -> False];
b = True];
Dynamic[Column[
Join[{"Item 1", "Item 2"},
If[Last@Last@Options[$FrontEnd, "VersionedPreferences"] === False &&
b == True, {Button[
Pane[Style[
"This FrontEnd uses shared preferences file. Press this \
button to set FrontEnd to use versioned preferences file (all the \
FrontEnd settings will be reset to defaults).", Red], 300],
AbortProtect[
SetOptions[$FrontEnd, "VersionedPreferences" -> True];
b = False]]}, {}]], Alignment -> Center],
Initialization :>
If[! Last@Last@Options[$FrontEnd, "VersionedPreferences"], b = True,
b = False]]
关键点是:
- 引入附加
Dynamic
变量b
并将其与 的值绑定Options[$FrontEnd, "VersionedPreferences"]
, - 用而不是使用
inside包装整个
Column
构造。Dynamic
Dynamic
Column