我在切换按钮时遇到麻烦。 在MainScreen中,有一个按钮将打开一个弹出窗口。 在弹出窗口中,有一个按钮,当按下该按钮时,将显示DisplayScreen。
这是我的python代码。
import Konva from 'konva'
import map from './../resources/unpar.svg'
const width = window.innerWidth
const height = window.innerHeight
// scale is temp
let stage = new Konva.Stage({
container: 'canvas',
width,
height,
offset: {
x: width / 2,
y: height / 2
},
x: width / 2,
y: height / 2
})
let layer = new Konva.Layer({draggable: true})
let testCircle = new Konva.Circle({
x: 633,
y: 590,
radius: 10,
fill: 'white',
stroke: 'black'
})
testCircle.on('mousemove', function () {
tooltip.position({
x: testCircle.x() - 90,
y: testCircle.y() - 50
})
tooltip.text('Pintu Depan Gedung 10')
tooltip.show()
layer.batchDraw()
})
testCircle.on('mouseout', function () {
tooltip.hide()
layer.draw()
})
var tooltip = new Konva.Text({
text: '',
fontFamily: 'Calibri',
fontSize: 18,
padding: 5,
textFill: 'white',
fill: 'black',
alpha: 0.75,
visible: false
})
let imageObj = new Image()
imageObj.onload = function () {
const map = new Konva.Image({
image: imageObj,
})
layer.add(map)
layer.add(testCircle)
layer.add(tooltip)
stage.add(layer)
}
imageObj.src = map
export default stage
这是我的奇异密码
#this is MainScreen class
class MainScreen(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def displayConfirmationDialog(self):
confirmationDialog = self.MainScreenConfirmationDialog()
confirmationDialog.setMessage()
confirmationDialog.open()
#this is the function of the button
def update(self):
self.displayConfirmationDialog()
#this is the popup class
class MainScreenConfirmationDialog(Popup):
def setYesButton(self):
screenManager.add_widget(DisplayScreen())
self.manager.current = 'display_screen'
#this is the DisplayScreen class
class DisplayScreen(Screen):
pass
当我运行它时,它显示了一个错误
<MainScreen>:
Button:
text: 'UPDATE'
on_press:root.update()
<MainScreenConfirmationDialog>:
GridLayout:
rows: 3
Label:
id: lbl_confirmation
Button:
id: b
text: 'YES'
on_press: root.setYesButton()
<DisplayScreen>:
name: 'display_screen'
GridLayout:
rows: 4
row_force_default: True
row_default_height: 40
Label:
text: 'HELLO'
id: lbl_display_name
答案 0 :(得分:0)
“弹出”窗口小部件无权访问屏幕管理器。
由于您可以访问全局变量screenManager
,因此将self.manager.current = 'display_screen'
替换为screenManager.current = 'display_screen'