Python代码在调用新函数之前不会等待tkinter结束或要接收串行数据

问题描述 投票:0回答:1

我有一个应该创建tkinter窗口并询问用户一些信息的程序。用户输入信息后,程序将从USB设备读取串行数据。最后,该程序应该将用户输入的信息和USB设备中的数据写入文件。

# Open a tkinter window to collect information from the user   
Window.create() 

# Receive the data from the USB Device 
MySerial.receive()

# Save all the data to a file
Report.create()

问题是,当我运行此代码时,将立即创建文件。它是在用户完成输入数据之前和接收USB数据之前创建的。如何停止呢?

Update: Window.create()创建一个新的tkinter窗口,然后设置该窗口的高度和位置。之后,它会调用我的Window类中的其他函数,从而在该tkinter窗口中创建文本和输入框。最后,它破坏了窗户。

def create():
# Create a window
global window
window = Tk()
window.title("My Title")

# Set the size and location of the window
screenWidth = window.winfo_screenwidth()
screenHeight = window.winfo_screenheight()
global windowWidth
windowWidth = 360
global windowHeight
windowHeight = 134
centerX = str(round((screenWidth-windowWidth)/2))
centerY = str(round((screenHeight-windowHeight)/2))
window.geometry(str(windowWidth)+"x"+str(windowHeight)+"+"+centerX+"+"+centerY) #'400x88+760+496'

# Set the font size
global fontSize
fontSize = 12

global messageCount
messageCount= 0

# First, get the users name
getNameMessage()

# Second, display a message
message()

# Third, get info from the user
infoMessage()

# Fourth, display another message
secondMessage()

# Destroy the window
window.destroy() # Create the window and global variables
python tkinter pyserial
1个回答
-2
投票

添加输入,因此用户必须按Enter或其他任何方式才能向前移动程序。

© www.soinside.com 2019 - 2024. All rights reserved.