当我运行pdflatex
、pythontex
和时pdflatex
,pythontex 引发错误:NameError: name x is not defined
。
但是当我用Python运行py文件时,它并没有给出错误。
梅威瑟:
\begin{filecontents*}[overwrite]{myFile.py}
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.geometry('300x200')
root.resizable(False, False)
root.title('Checkbox Demo')
agreement = tk.IntVar()
def print_changed():
global x
x = r"\setboolean{mybool}{true}" if agreement.get() else r"\setboolean{mybool}{false}"
ttk.Checkbutton(root,
text='I agree',
command=print_changed,
variable=agreement,
onvalue=1,
offvalue=0).pack()
root.mainloop()
\end{filecontents*}
\documentclass{article}
\usepackage{pythontex}
\usepackage{ifthen}
\begin{document}
\newboolean{mybool}
\begin{pycode}
import myFile
\end{pycode}
\py{x}
\ifthenelse{\boolean{mybool}}{%
Print report
}{%
Do not print report
}
\end{document}