2015-10-22 62 views
1
import wpf 

from System.Windows import Application, Window,MessageBox 
from Main import * 
from Sign_Up import * 

import System 
from System.Windows.Controls import * 
from System.Windows.Input import * 
from System import Uri 
from System.Windows.Media.Imaging import BitmapImage 
from System.Windows.Media import ImageBrush 

class MyWindow(Window): 
    def __init__(self): 
     wpf.LoadComponent(self, 'Sign_In.xaml') 
     brush = ImageBrush() 
     image = Image() 
     image.Source = BitmapImage(Uri("C:\Users\Chen\Pictures\1-150511225359.jpg")) 
     brush.ImageSource = image.Source 
     self.SignUpGrid.Background = brush 

我試圖在wpf IronPython中設置一個窗口的背景圖像,我不斷收到語法錯誤。設置python的背景圖像

+0

你得到什麼錯誤? – wmk

+0

我正在使用Visual Studio和IronPython,它只給我一般的錯誤區域而不是錯誤 –

回答

1

您應該在路徑名中使用雙重\。你不需要中間的圖像控制。

def __init__(self): 
    wpf.LoadComponent(self, 'Sign_In.xaml') 
    brush = ImageBrush() 
    brush.ImageSource = BitmapImage(Uri("C:\\Users\\Chen\\Pictures\\1-150511225359.jpg")) 
    self.SignUpGrid.Background = brush 

或者更短:

def __init__(self): 
    wpf.LoadComponent(self, 'Sign_In.xaml') 
    self.SignUpGrid.Background = ImageBrush(BitmapImage(Uri(
     "C:\\Users\\Chen\\Pictures\\1-150511225359.jpg"))) 
+0

非常感謝!有用 –