附加是我在Tkinter中使用畫布構造的GUI的一部分,因此可以在背景中插入圖像。 當我調用函數Relay_1時:結果被髮送到Python shell窗口。 我想要的是畫布中的文本框,並在畫布上顯示結果(即打印結果),而不是在外殼中。 任何想法,將不勝感激。將結果打印到畫布不是殼窗口
import Tkinter
#Function
def Relay_1():
arduinoData.write(b'1')
print ("This is a test\n")
class ProgramGUI:
def __init__(self):
# Creates the Main window for the program
self.main = tkinter.Tk()
# Change Default ICON
self.main.iconbitmap(self,default = 'test.ico')
# Create title, window size and make it a non re sizable window
self.main.title('Test')
self.main.resizable(False, False)
self.main.geometry('680x300')
self.canvas = tkinter.Canvas(self.main, width = 680, height = 300)
self.canvas.pack()
self.logo = tkinter.PhotoImage(file = 'test.png')
self.canvas.create_image(0,0,image = self.logo, anchor = 'nw')
# Create 3 Frame to group the widgets
self.top = tkinter.Frame(self.main)
self.middle = tkinter.Frame(self.main)
self.bottom = tkinter.Frame(self.main)
等等等等
我設置了一行代碼如下 – John