【问题标题】:raw input through tkinter entry widget [duplicate]通过 tkinter 条目小部件的原始输入 [重复]
【发布时间】:2018-07-24 14:52:54
【问题描述】:
from tkinter import *
import matplotlib.pyplot as plt
window = Tk()

entryBox = Entry(window,text='input latex command')
entryBox.grid(row=0,column=0)

s = '$\sum {n} = \frac{n(n+1)}{2}$'
plt.text(.5,.5, s, fontsize=40)
plt.show()

这个sn-p只显示部分表达式如下:

而不是预期的结果:

(这是通过将第 7 行更改为:plt.text(.3,.3, r'$\sum {n} = \frac{n(n+1)}{2}$', fontsize=40))。

我的理解是,在第一种情况下,我们不会将字符串作为原始字符串传递。当我将字符串作为字符串变量但不能将其作为字符串文字输入时,如何让绘图正确呈现?

【问题讨论】:

  • 如果你写s = r'$\sum {n} = \frac{n(n+1)}{2}$'(即在字符串前面添加r),它会按预期工作。
  • 另见this
  • 为什么不能输入字符串文字?
  • 我的意思是我不能将字符串作为文字传递,因为字符串是通过条目小部件来的。 @Nae

标签: python-3.x matplotlib tkinter raw-input tkinter-entry


【解决方案1】:

使用以下方法过滤您的字符串:

s = s.replace("\x0c", "\\f")

显然是thisdoesn't work on frac formfeed

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    相关资源
    最近更新 更多