English 中文(简体)
我如何用pin子轮轮流使用 t子。
原标题:How do I make tkinter text rotate with a spinning wheel?

这是我第一次利用四舍五入,因此,如果格式错,我会抱歉。

I m trying to make this function do 2 things. First, I m drawing a wheel with an amount of fields equal to the amount of descriptions given, with field having a different hue of a given color. Then, the text for each option is given via the array of strings, and this text should be put inside each of the fields on the wheel. I have figured out where to place the text, but I can t seem to get the rotation down.

    def drawWheel(self):
        """
        Draws the GUI wheel with a random selection of colors. Uses amount of string objects as amount of fields
        """
        anglePerSection = 360 / self.sections
        x0, y0, x1, y1 = 30, 30, 570, 570
        radius = 250
        centerX, centerY = 300, 300
        self.canvas.create_oval(x0, y0, x1, y1, fill="white")

        for i, description in enumerate(self.descriptions):
            startAngle = anglePerSection * i + self.angle
            txtStartAngle = anglePerSection * i - self.angle
            self.canvas.create_arc(x0, y0, x1, y1,
                                   start=startAngle,
                                   extent=anglePerSection,
                                   fill=self.getColorBrightness(self.color, i),
                                   outline="black")
            midpointAngle = (txtStartAngle + (anglePerSection / 2)) % 360
            angle_rad = np.radians(midpointAngle)
            textX = centerX + radius * np.cos(angle_rad)
            textY = centerY + radius * np.sin(angle_rad)
            self.canvas.create_text(textX, textY, text=description, font=("Arial", 14), fill="white", angle=anglePerSection * i + startAngle)

        self.canvas.create_oval(centerX - 85, centerY - 85, centerX + 85, centerY + 85, fill="white")

采用<代码>自行.canvas.create_text(textX, textY, text=description, font=(Arial), 14),填充“white”, 角=midpointAngle-90 % 360), 角逐段应当计算案文所需的轮换。 然而,在我一生中,我无法看到正确的轮换。

I ve tried a few different calculations, mainly using anglePerSection * i + startAngle with no luck. The good news is, the text rotation angle stays consistent with this calculation, so I m thinking I just need to add some constant value to orient all the numbers correctly. They should of course be oriented so the text fills the field from the edge to the center.

Edit: Minimum reproduable example

import tkinter as tk
import numpy as np


if __name__ ==  __main__ :
    root = tk.Tk()
    sections = 21
    numberList = [str(i) for i in range(1, sections + 1)]
    canvas = tk.Canvas(root, width=600, height=600)
    canvas.pack()
    anglePerSection = 360 / sections
    x0, y0, x1, y1 = 30, 30, 570, 570
    radius = 250
    centerX, centerY = 300, 300
    canvas.create_oval(x0, y0, x1, y1, fill="white")
    for i, number in enumerate(numberList):
        startAngle = anglePerSection * i
        canvas.create_arc(x0, y0, x1, y1,
                          start=startAngle,
                          extent=anglePerSection,
                          fill="white",
                          outline="black")
        midpointAngle = (startAngle + anglePerSection / 2) % 360
        angle_rad = np.radians(midpointAngle)
        textX = centerX + radius * np.cos(angle_rad)
        textY = centerY + radius * np.sin(angle_rad)
        canvas.create_text(textX, textY, text=number, font=("Arial", 14), fill="black", angle=anglePerSection * i + startAngle)

    root.mainloop()

该法典产生了一个有多个领域的圈子。 离“一米”方向最接近11。 这里还有一点要补充,我也很难把人数的下半点推到底,但我稍后将对此感到关切。

问题回答

您计算出了<代码>textY错,应当:

textY = centerY - radius * np.sin(angle_rad)

这是因为,从上到下游的血管。

Also the value of midpointAngle is what you want on the angle option of the text item:

canvas.create_text(textX, textY, text=number, font=("Arial", 14),
                   fill="black", angle=midpointAngle)

产出:

“entergraph

Or angle=midpointAngle-90:

“在此处的影像描述”/</a





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签