使用 Enthought 的 Canopy,tkinter radiobutton 和 mainloop 在 python3 中无法正常工作
tkinter radiobutton and mainloop not working properly in python3, using Enthought's Canopy
我正在使用 Enthought Canopy(用于数据采集)开发一个 python 程序。但是,在 python 3.5 环境中工作时,我在使用 tkinter 时遇到问题。我无法使用 var.get()
函数获取单选按钮的值。 (在使用整数时将其定义为 tk.IntVar()
或在我的示例代码中将其定义为 tk.StringVar()
)
此外,当按下退出按钮时主循环不会停止,tkinter window 关闭但程序保持 运行。
当切换到python 2.7 环境时,我没有这些问题。下面是代码的精简版本。
在此先感谢您的帮助
import tkinter as tk
class GUI:
def __init__ (self, master):
self.master = master #Defining the root window
#Create container
frame = tk.Frame(master)
#Defining the labels
fontName = 'Helvetica 10'
self.waveform = tk.StringVar()
self.sawtoothRadio = tk.Radiobutton(frame, text='Sawtooth',
variable=self.waveform, value="sawtooth")
self.triangleRadio = tk.Radiobutton(frame, text='Triangle',
variable=self.waveform, value="triangle")
self.triangleRadio.select()
self.startButton = tk.Button(frame, text="Start", font = fontName, command=self.calibrate)
#Structuring the GUI
self.sawtoothRadio.grid(row=9, column=0)
self.triangleRadio.grid(row=9, column=1)
self.startButton.grid(row=10, column=1)
frame.pack(side=tk.LEFT)
def draw_graph(self, right_frame):
#Plotting the graph
if self.waveform.get() == "sawtooth":
sawtooth = True
else:
sawtooth = False
def calibrate(self):
#Plotting the graph
if self.waveform.get() == "sawtooth":
sawtooth = True
else:
sawtooth = False
root = tk.Tk()
newWindow = GUI(root)
root.mainloop()
所以我终于发现问题似乎出在 Enthought 的 Canopy 上。
程序在PyCharm 和Anaconda 的Spyder 中都可以正常运行,但是我仍然不知道是什么导致了Canopy 中的问题。但是使用另一个 IDE 似乎可以解决问题。
我正在使用 Enthought Canopy(用于数据采集)开发一个 python 程序。但是,在 python 3.5 环境中工作时,我在使用 tkinter 时遇到问题。我无法使用 var.get()
函数获取单选按钮的值。 (在使用整数时将其定义为 tk.IntVar()
或在我的示例代码中将其定义为 tk.StringVar()
)
此外,当按下退出按钮时主循环不会停止,tkinter window 关闭但程序保持 运行。
当切换到python 2.7 环境时,我没有这些问题。下面是代码的精简版本。
在此先感谢您的帮助
import tkinter as tk
class GUI:
def __init__ (self, master):
self.master = master #Defining the root window
#Create container
frame = tk.Frame(master)
#Defining the labels
fontName = 'Helvetica 10'
self.waveform = tk.StringVar()
self.sawtoothRadio = tk.Radiobutton(frame, text='Sawtooth',
variable=self.waveform, value="sawtooth")
self.triangleRadio = tk.Radiobutton(frame, text='Triangle',
variable=self.waveform, value="triangle")
self.triangleRadio.select()
self.startButton = tk.Button(frame, text="Start", font = fontName, command=self.calibrate)
#Structuring the GUI
self.sawtoothRadio.grid(row=9, column=0)
self.triangleRadio.grid(row=9, column=1)
self.startButton.grid(row=10, column=1)
frame.pack(side=tk.LEFT)
def draw_graph(self, right_frame):
#Plotting the graph
if self.waveform.get() == "sawtooth":
sawtooth = True
else:
sawtooth = False
def calibrate(self):
#Plotting the graph
if self.waveform.get() == "sawtooth":
sawtooth = True
else:
sawtooth = False
root = tk.Tk()
newWindow = GUI(root)
root.mainloop()
所以我终于发现问题似乎出在 Enthought 的 Canopy 上。
程序在PyCharm 和Anaconda 的Spyder 中都可以正常运行,但是我仍然不知道是什么导致了Canopy 中的问题。但是使用另一个 IDE 似乎可以解决问题。