1

I'm coding a visual novel for a school project and I want to incorporate a mini-game made with python and tkinter. How can I do this?

I copied the code into renpy but renpy says "statement expected", and I don't think I'm doing it the right way. Thank you in advance!

label start:
"Welcome!"


from tkinter import *
window=Tk()
window.title('Hello Python')
window.geometry("300x200+10+20")
window.mainloop()
return

What I get: "from tkinter import-->* expected statement"...

A human
  • 23
  • 5
  • Please provide a minimal reproducible example. https://stackoverflow.com/help/minimal-reproducible-example Also imo it kind of sounds like your tabbing might be off or something, you're getting a syntax error. But it would be much easier to figure out what's going on with some code. – Brock Brown Apr 04 '23 at 18:10
  • Glancing at the [documentation](https://www.renpy.org/doc/html/quickstart.html#supporting-flags-using-the-default-python-and-if-statements), lines of arbitrary Python code needs to be prefixed with a `$`. – chepner Apr 04 '23 at 18:44
  • I've added a $ before every line, and renpy tells me there's no module names tkinter. After looking into it, looks like it can't be added as it is not a pure module. Is there any other way? Maybe add a button that opens the file? – A human Apr 04 '23 at 18:49
  • 1
    Your first line breaks the code so I do not think you are even getting to the from tkinter statement. – Mike - SMT Apr 04 '23 at 19:00
  • If renpy runs on a server, you almost certainly won’t be able to run tkinter. – Bryan Oakley Apr 04 '23 at 21:52
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 04 '23 at 22:45

1 Answers1

1

There is a way to launch other application (any application not only Python code) from RenPy code. Let's say this is your RenPy code:

$import os

label start:

    "Welcome!"
    $os.system(r"c:\renpy_test\game.py")

And here is your Tkinter game stored in c:\renpy_test\game.py:

import tkinter as tk
window = tk.Tk()
window.title('Hello Python')
window.geometry("300x200+10+20")
window.mainloop()

When you launch your RenPy game it then launches your Tkinter app:

enter image description here

Alderven
  • 7,569
  • 5
  • 26
  • 38
  • my window opens in thonny instead of opening directly. Howcan I fix that? – A human Apr 05 '23 at 15:02
  • 1
    Simplest way is to remove Thonny and install [Python](https://www.python.org/downloads/) and [RenPy](https://www.renpy.org/latest.html) – Alderven Apr 05 '23 at 19:12