내 문제는 이것입니다. 배경 이미지가 멋지다. 창 크기를 다시 조정하면 이미지가 움직이게되지만 로그인 클래스에서는 'check-icon.png'가 전혀 표시되지 않습니다. 로그에로드되었다고 표시되어 있지만 창에 아무 것도 없습니다. 또한 로그인 클래스 문을 변경하여 말 :화면 크기 변경 Kivy 이미지 업데이트
with self.canvas.before:
self.image = Image(stuff)
대신
with root.canvas.before:
self.image = Image(stuff)
을 내가 체크 icon.png를 표시 얻을 수 있습니다 (루트 자체로 변경)하지만 여전히 재조정하지 않는 경우 창 크기는 배경 이미지가 맨 아래처럼 바뀝니다.
import kivy
kivy.require('1.8.0') # current kivy version
import ConfigParser
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.image import Image
from kivy.graphics import Rectangle
class login(Widget):
#checking to see if the user logging in has privilage to access program
def validate(self, *args):
username = self.ids['user']
user = username.text
config = ConfigParser.ConfigParser()
config.read('Privilage.cfg')
if not config.has_section('users'):
print 'the Privilage.cfg file has been tampered with'
if not config.has_option('users',user):
print 'user is not listed'
else:
userPriv = config.get('users',user)
print 'user',user,'has privilage',userPriv
valid = '/Users/Kevin/Desktop/Python-extras/SSS Assistant/Manager_images/check-icon.png'
#Put a check or x next to username based on if its in the system
self.root = root = login()
root.bind(size=self._update_image,pos=self._update_image)
with root.canvas.before:
self.image = Image(source=valid, pos=((self.width/2)+130,(self.top/2)), size=(25,25))
def _update_image(self,instance,value):
self.image.pos = instance.pos
self.image.size = instance.size
class DataApp(App):
def build(self):
#login is the root Widget here
self.root = root = login()
root.bind(size=self._update_rect,pos=self._update_rect)
with root.canvas.before:
self.rect = Rectangle(source="/Users/Kevin/Desktop/Python-extras/SSS Assistant/Manager_images/background.jpg",size=root.size,pos=root.pos)
return root
def _update_rect(self,instance,value):
self.rect.pos = instance.pos
self.rect.size = instance.size
if __name__ == '__main__':
DataApp().run()
또한이 슈퍼 긴 것을 게시했습니다. 정말 관련성이 높은 코드 만 게시해야한다는 것을 알고 있지만이 코드를 처음 접했을 때 코드의 다른 부분에 실수가 없는지 확인하고 싶었습니다.
self.bind(size=self._update_image,pos=self._update_image)
#Put a check or x next to username based on if its in the system
self.image = self.add_widget(Image(source=valid, pos=((self.width/2)+115,(self.top/2)+50), size=(20,20)))
def _update_image(self,instance,value):
self.image.pos = instance.pos
self.image.size = instance.size
이미지는 캔버스 명령이 아닌 위젯입니다. 'self.add_widget (Image (...)) '와 함께 추가하십시오. – inclement
이미지를 추가하지만 창 크기를 조정해도 여전히 변경되지 않습니다. – Bystander001