[Python] How to navigate between two pages in XAML and win32more

Discussão em 'Python' iniciado por Stack, Setembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    I want to create a window desktop UI and I am stuck on navigation between tow pages in XAML and win32more so help me to fix this problem. Firstly I create a page using XAML and run this application using win32more.In win32more code I find the button but this code send back a error is button not found so tell me how can i fix this issue.

    this is the win32more code.
    from win32more.xaml import XamlApplication
    from win32more.Microsoft.UI.Xaml import Window
    from win32more.Microsoft.UI.Xaml.Controls import Page, Button, Frame
    from win32more.Microsoft.UI.Xaml.Markup import XamlReader

    class MainPage(Page):
    def __init__(self, frame):
    super().__init__()
    self.frame = frame
    try:

    with open("page1.xaml", "r") as file:
    self.Content = XamlReader.Load(file.read())
    if self.content:
    print("xaml content loaded succesfuly...")
    else:
    print("xaml content not loaded..")

    except Exception as e:
    print(f"cann't load file...{e}")

    get_started_button = self.FindName("GetStartedButton")
    if get_started_button:
    print("Button found!")
    get_started_button.Click += self.GetStartedButton_Click
    print(get_started_button)
    else:
    print("button not found")

    def GetStartedButton_Click(self, sender, e):


    second_page = SecondPage()
    self.frame.Navigate(second_page)


    class SecondPage(Page):
    def __init__(self):
    super().__init__()

    with open("page2.xaml", "r") as file:
    self.Content = XamlReader.Load(file.read())

    class App(XamlApplication):
    def OnLaunched(self, args):
    win = Window()
    win.Title = ""
    win.ExtendsContentIntoTitleBar = True
    win.SetTitleBar(None)
    frame = Frame()

    main_page = MainPage(frame)
    frame.Content = main_page
    win.Content = frame

    win.Activate()

    XamlApplication.Start(App)



    this is XAML code.
    <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    >
    <Grid Background="White">
    <Grid.RowDefinitions>
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="*"/>
    <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <Image Source="https://gurpreetsingh.aliens.school/whatsapp.png"
    Width="450" Height="550" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,155,0,0"/>

    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,455,0,0">
    <TextBlock Text="Welcome to WhatsApp" FontSize="24" Padding="10" HorizontalAlignment="Center" />
    <TextBlock Text="A simple, reliable, and private way to use WhatsApp on your computer." FontSize="13" Padding="10" HorizontalAlignment="Center" Margin="0,2,0,0" />
    <Button Name="GetStartedButton" Content="Get Started" Click="GetStartedButton_Click" />
    <TextBlock Text="Version 2.2247.3.0" FontSize="14" Padding="10" HorizontalAlignment="Center" Margin="0,15,0,0" />
    </StackPanel>
    </Grid>
    </Page>

    Continue reading...

Compartilhe esta Página