gpt4 book ai didi

wolfram-mathematica - 柱内自毁按钮

转载 作者:行者123 更新时间:2023-12-01 08:38:59 24 4
gpt4 key购买 nike

如何创建一个Button,仅当某些全局FrontEnd设置的值为False时才会显示,并且会随着的整行自毁列按下后将此值设置为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"],
  • 的值绑定(bind)
  • 包装整个 Column 构造使用 Dynamic 而不是使用内的动态

最佳答案

也许

PreemptProtect[SetOptions[$FrontEnd, "VersionedPreferences" -> False]; b = True]; 

Column[{"Item 1", "Item 2", Dynamic[
If[Last@Last@Options[$FrontEnd, "VersionedPreferences"]===False && b == True,
Button["Here!", SetOptions[$FrontEnd, "VersionedPreferences"->True];b=False],
"Done"]]}]

编辑

回答您的评论。请尝试以下方法。用 Dynamic[ ] 包含 Column[ ] 可以调整它的大小:

PreemptProtect[SetOptions[$FrontEnd, "VersionedPreferences" -> False]; b = True]; 
Dynamic[
Column[{
"Item 1",
"Item 2",
If[Last@Last@Options[$FrontEnd, "VersionedPreferences"] === False && b == True,
Button["Press me!", SetOptions[$FrontEnd, "VersionedPreferences" -> True]; b=False],
Sequence @@ {}]}]]

关于wolfram-mathematica - 柱内自毁按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6387132/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com