当我按空格键时,我正在尝试设置一个小部件。我有一个包含 QLabel 的 QGridLayout。我想从 QGridLayout 中的坐标设置特定 Qlabel 的文本,但是当我从按键函数访问 QGridLayout 时,该变量为空。
import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget
from PyQt5.QtCore import QSize
class Position:
def __init__(self, x, y):
self.x = x
self.y = y
class HelloWindow(QMainWindow):
global gridLayout
def __init__(self):
QMainWindow.__init__(self)
self.setMinimumSize(QSize(640, 640))
self.setWindowTitle("Hello world")
centralWidget = QWidget(self)
self.setCentralWidget(centralWidget)
gridLayout = QGridLayout(self)
gridLayout.setSpacing(0)
centralWidget.setLayout(gridLayout)
file_text = open("logic/file.txt", "r")
file = file_text.read()
file = file.replace("[(","")
file = file.replace(")]","")
file = file.replace("),(",";")
positions = file.split(';')
lista …Run Code Online (Sandbox Code Playgroud) 我正在尝试从标题按钮导航,但我不能,因为找不到导航变量。
这是我的代码
export const createRootNavigator = (signedIn = false) => {
return StackNavigator(
{
SignedIn: {
screen: SignedIn,
navigationOptions: {
gesturesEnabled: false,
headerStyle,
headerTintColor: "white",
headerTitleStyle,
headerLeft: null,
headerRight: <TouchableOpacity style={ [{paddingHorizontal:15}] }
onPress={() => navigation.navigate({ routeName: 'Notification'})}>
<Icon
name="md-notifications-outline"
size={26}
style={{ color: "white" }}/>
</TouchableOpacity>,
}
},
SignedOut: {
screen: SignedOut,
navigationOptions: {
gesturesEnabled: false
}
},
Notification: {
screen: Notification,
navigationOptions: {
gesturesEnabled: false
}
}
},
{
mode: "modal",
initialRouteName: signedIn ? "SignedIn" : "SignedOut"
}
); …Run Code Online (Sandbox Code Playgroud)