#welcome Player 1 and print the players name
player1 = sc.textinput("Name of Player X", "Whats your name? ")
movingTurtle.penup()
movingTurtle.goto(-275, 240)
movingTurtle.pendown()
sc.wel_Player1 = movingTurtle.write("Welcome Player X: "+player1,
font=FONT2)
this code works fine , a little "message-box" pop´s up and asks the 1st player for his name -- the problem is that i cant change the position of that TEXTINPUT-BOX -- i dont even know, if this is possible
I've had the same question and I've looked everywhere for an answer!
Unfortunately, from what I've found, there doesn't seem to be any way to modify the position or general look of a textinput box.
Have a look at -> This similar post
This might be what you're looking for.
If anyone can actually propose a different way, that would be much appreciated however my conclusion is that a textinput dialog box cannot be modified sadly.
What I've done is commit to the look by adding a black backdrop-type box behind it and making it a bit more obvious and professional that way.
#the black backdrop
useroptionboxback = turtle.Turtle()
useroptionboxback.speed(0)
useroptionboxback.shapesize(stretch_wid=6.8,stretch_len=10)
useroptionboxback.shape('square')
useroptionboxback.color('black')
useroptionboxback.penup()
useroptionboxback.goto(-215,255)
useroptionboxback.direction = 'stop'
#the tetinput box
title1 = 'Menu'
prompt1 = 'Please type a number.'
useroptionbox = turtle.textinput(title1, prompt1)
wn.update()
Example Screenshot
I would recommend doing something like this if you find what the guy on the link is saying too confusing.
Related
I am working on a color matching learning game. When you click the colored square, a pop up window will show you the name of the color, typed in the corresponding color, as well as pronounce the color.
During development, I ran into an issue where tkinter would not display my .gif image (which is the typed color) on the top level window, which opens after a color is selected.
I started adding additional widgets to the top level window to attempt to figure out the issue.
However, I accidentally left of the parentheses at the end of pack on the second label I added.
Sure enough, my image showed.
When I went back to add the missing parentheses, my image stopped showing??
def callback(event):
print ("clicked at", event.x, event.y)
if 30 < event.x < 120:
print("Red")
top = tk.Toplevel()
diagrams = tk.PhotoImage(file='Red.gif')
logolbl= tk.Label(top, text = "Red", image = diagrams).pack()
btn = tk.Button(top, text="Back").pack()
##### this is the label I am referring to #####
tk.Label(top, text = "why does this fix it?").pack
if 150 < event.x <240 :
print("Green")
if 270 < event.x < 370:
print("Blue")
This is a screen shot of it displaying the image, with the missing parentheses
This is a screen shot of the second label commented out, and my image not showing
Has anyone experienced this?
I mean technically I can work with this, however, I understand it is incorrect.
I'd like to have an understanding of what I am doing wrong, and what is happening "behind the scenes"
All,
I am trying to build a small UI as a wrapper for a tool I have. I am trying to use ipywidgets in Jupyter notebooks to do this and I am running into a small issue. It is not sufficiently clear by looking at the Read The Docs page as to how it can be addressed, so any guidance would be greatly appreciated.
Here is what I am looking at, this is straight from the documentation:
```
import ipywidgets as widgets
tab_contents = ['P0', 'P1', 'P2', 'P3', 'P4']
children = [widgets.Text(description=name) for name in tab_contents]
tab = widgets.Tab()
tab.children = children
tab.titles = [str(i) for i in range(len(children))]
tab
```
This looks great, except that the tabs do not have a title. The documentation basically says, titles can be set the same way as Accordion container, but even that container doesn't show how to set a title. Would appreciate any help in this matter.
Best
Uday
Yep it's not the most obvious way to do it. Here is an alternative that avoids a list comprehension.
for title, (index, _) in zip(tab_contents, enumerate(tab.children)):
tab.set_title(index, title)
I found an answer here:
from ipywidgets import *
names = ['General', 'Representation', 'Preference', 'Theme', 'Extra', 'Help']
tab = Tab([IntSlider(description='hi') for _ in names])
[tab.set_title(i, title) for i, title in enumerate(names)]
tab
I have been tinkering with Tkinter the last couple of days to create a little game.
I have searched for how to display text ontop of an image label but there is a little downside, it won't display exactly at the spot i am looking(in this case the top left side of the label).
I tried anchor and compound together in the same label but it doesn't seem to do anything new
the text still remains in the middle.
The code looks like this:
'''Adjusting the information frame'''
self.image_info = PhotoImage(file=locate_images("_info_panel", ""))
self.label_text_info = "• Welcome to Agony,\nto play or read the rules please go to File"
self.label_info = Label(self.info, text=self.label_text_info, font=10, image=self.image_info, compound=CENTER, anchor=NW)
self.label_info.grid(row=0, column=0)
Edit:
If I try to add anything else other than compound=CENTER the text is displayed outside the boundingbox of the image on the specified side.
Moved from an edit to the question by the OP to an answer.
Use a Canvas:
'''Adjusting the information frame'''
self.image_info = PhotoImage(file=locate_images("_info_panel", ""))
self.label_text_info = "• Welcome to Agony,\nto start the game or read the rules please go to File"
self.canvas_info = Canvas(self.info, width=300, height=600)
self.canvas_info.create_image((0, 0), image=self.image_info, anchor=NW)
self.canvas_info.create_text((140, 25), text=self.label_text_info)
self.canvas_info.grid(row=0, column=0)
I was approaching it wrong from the start, I am fearly new to tkinter
and I had to use a canvas to display the items inside of.
I created a new path2d following the instructions in the my first game article: http://docs.godotengine.org/en/3.0/getting_started/step_by_step/your_first_game.html
I wanted to move the "box" on screen so that I could see how the mobs spawn in, but when I ran the scene, it stayed off screen.
I created a new path2d, centered this one in the middle of the screen, and it works like I wanted it to, but now I moving this one in the editor doesn't update the position in game.
What's going on?
Thanks
func _on_mobtimer_timeout():
$mobtimer.wait_time = 0.1 + randf() / 2
$mobspawn/moblocation.set_offset(randi())
var mob = Mob.instance()
add_child(mob)
var direction = $mobspawn/moblocation.rotation + PI/2
mob.position = $mobspawn/moblocation.position
direction += rand_range(-PI/8, PI/8)
mob.rotation = direction
mob.set_linear_velocity(Vector2(rand_range(200, 200 + score * 30), 0).rotated(direction))
A Node2D's position property is relative to it's parent's position. The code from the Dodge The Creeps tutorial assumes that MobPath is located at 0, 0 and fails when that assumption is false.
In your case you are taking a MobSpawnLocation's position relative to MobPath and then setting it as the new Mob's global position.
Luckily Node2D's have another property that we can use in these circumstances global_position. It can be used like this:
mob.position = $mobspawn/moblocation.global_position
http://docs.godotengine.org/en/stable/classes/class_node2d.html#member-variables
This isn't a full solution, but I found a weird workaround. Instead of changing the position in the editor, if you use the nodes on the orange box (at the intersection of orange and blue), you can kind of alternate to move the box around.
So in my game, you want to make the potato as big as possible. The first time you play it, the highscores work fine,giving you a highscore and saving it. The problem is that whenever you play the game, the highscore is always reset to your current score, which means that even if you get a lower score then your previous highscore, it saves your current score as the highscore. my code looks like this:
var savedstuff:SharedObject = SharedObject.getLocal("myStuff");
if (savedstuff.data.bestScore = 0) {
savedstuff.data.bestScore = 1
}
bigness.text = finish.toString();
if (finish > savedstuff.data.bestScore){
savedstuff.data.bestScore = finish;
}
best.text = savedstuff.data.bestScore.toString();
savedstuff.flush();
where bigness is a textbox displaying your current score, best is a textbox displaying your highscore and bestScore is where the best score is stored. I have the line "if (finish > savedstuff.dada.bestScore)" which should make the overwrite only occur if you get a higher score, but it seems to just ignore that line. my game is here
http://www.kongregate.com/games/pwnedcat/grow-a-potato
any help is appreciated. I just started flash so I really don't know anything. :(
Check the condition, it should be
savedstuff.data.bestScore == 0
Instead of
savedstuff.data.bestScore = 0